-1

I want to create a signature with openssl. I have an executable command like the following, but I don't know how to translate it to PHP.

openssl cms -sign -inkey key.pem -signer signature.pem -outform DER -in xy.xml 

How to call this command in PHP?

Irgendw Pointer
  • 1,770
  • 3
  • 30
  • 67

2 Answers2

2
exec('openssl cms -sign -inkey key.pem -signer signature.pem -outform DER -in xy.xml')

With this command you make php call the openssl command of the operating system, like you do when you write it on a terminal.

If you want to do it in a native way (php functions) you can take a look at the OpenSSL library http://php.net/manual/en/book.openssl.php and the function sign http://php.net/manual/en/function.openssl-sign.php

Uxío
  • 1,333
  • 11
  • 12
  • 4
    Please add some explanation to your answer. Code-only answers are (sometimes) good enough, but Code+explanation answers are always better – Barranka Oct 01 '14 at 16:35
  • I was looking through the OpenSSL library, but I couldn't figure out how to execute the function with the preferred parameters in PHP. Therefore I asked the question. Because the sign function do not provide the used parameters and the pkcs7 function has restrictions. So I will use the shell_exec function anyway. – Irgendw Pointer Oct 02 '14 at 06:36
-2
openssl_cms_sign('xy.xml', "xy.xml.sign", file_get_contents('signature.pem'), file_get_contents('key.pem'), null, 0, OPENSSL_ENCODING_DER)
RiveN
  • 2,595
  • 11
  • 13
  • 26