title: Encrypt Data by using Digital signature in PKCS7 format with base 64 encoding
body: <p>We are writing to validate user data by using API. For validating purpose, i need to pass two variable in post method call and Two variables are data and signature. So Digital signature of data in PKCS7 format with base 64 encoding.</p>
  
  <p>For encryption they gave pem file to encrypt the data to generate signature in PKCS7 format with base 64 encoding.</p>
  
  <p>So kindly advise me how to do this encryption and i am doing this project in PHP.</p>
  
  <p>Also i have tried with following code but no results</p>
  
  <pre><code>$data = 'Test Data';
  $key = file_get_contents("certificate.pem");
  $fp = fopen("msg.txt", "w");
  fwrite($fp, $data);
  fclose($fp);
  openssl_pkcs7_encrypt("msg.txt", "enc.txt", $key,[]);
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>MIME-Version: 1.0
  Content-Disposition: attachment; filename="smime.p7m"
  Content-Type: application/x-pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"
  Content-Transfer-Encoding: base64
  
  MIICCgYJKoZIhvcNAQcDoIIB+zCCAfcCAQAxggG1MIIBsQIBADCBmDCBkDELMAkG
  A1UEBhMCSU4xKjAoBgNVBAoTIWVNdWRocmEgQ29uc3VtZXIgU2VydmljZXMgTGlt
  aXRlZDEdMBsGA1UECxMUQ2VydGlmeWluZyBBdXRob3JpdHkxNjA0BgNVBAMTLWUt
  TXVkaHJhIFN1YiBDQSBmb3IgQ2xhc3MgMyBPcmdhbmlzYXRpb24gMjAxNAIDI2nL
  MA0GCSqGSIb3DQEBAQUABIIBAEoKNU5O/NSlM62cVyq1CJ2qN6VA0kDRJaJVrUze
  Tbd8OJZdzdcn3T+ZNh2myDRliW3B8Q+u4qZN8NZ1GM9e5OkmdxgWPD0wDhUZyMhu
  796XOIdlZVLlyaNDr/QGYb4XxFrsJAqMXYFh3QPIATHhpaBGTnlB2fvFwtLSHocv
  TzGT/UgL9aS3BiDh/S7sULsOXZoMNlHP4rnzRnjRsU+QJogtYnKBXGcKuzxeXRDL
  dd7OxHTDgf4MFJcBdwdk6xwtbrVfyNCnIwzzFC4UwR5I/w6js+sBTg+EXAcCZqtG
  rouNxu+SBkYMh63r+5LX0C8rL6xp6jzt49dgttKxh8Q+xc0wOQYJKoZIhvcNAQcB
  MBoGCCqGSIb3DQMCMA4CAgCgBAiKcFDFzN93RIAQprj+fHrW8KA1XSSEY0fH3Q==
  </code></pre>
  
  <p>But it is not accepted from remote. Please help me</p>
  
  <p>Thank you</p>