digital signature in pkcs7 format with base64 encoding PHP

362 Views Asked by At

Is any pre-define function in PHP for making signature in pkcs7 format? I have .pfx certificate with me

1

There are 1 best solutions below

0
Sameer On

Below is the code for creating signature:

if(openssl_pkcs7_sign(realpath($input_file),realpath($output_file),'file://'.realpath('Your certificate path'),
        'file://'.realpath('Your private key path'),
        array(),
        PKCS7_NOINTERN
        )) {

            $data = file_get_contents($output_file);
            $begin = 'Content-Transfer-Encoding: base64';
            echo $data = trim(substr($data, strpos($data, $begin)+strlen($begin)));

        }else{
            echo $error = 'Failed to encrypt';
        }