Sign digital signature with PHP

How do I sign a digital signature using PHP?

+3


source to share


1 answer


To the right of the documentation for openssl_sign ()

//data you want to sign
$data = 'my data';

//create new private and public key
$new_key_pair = openssl_pkey_new(array(
    "private_key_bits" => 2048,
    "private_key_type" => OPENSSL_KEYTYPE_RSA,
));

openssl_pkey_export($new_key_pair, $private_key_pem);

//create signature
openssl_sign($data, $signature, $private_key_pem, OPENSSL_ALGO_SHA256);

echo base64_encode($signature);

      



Of course, if you already have the private key, you can omit it and just use it as a parameter $private_key_pem

in the openssl_sign()

.

+2


source







All Articles