Sign a string with a private key using PHP

Sign a string with a private key using PHP

How to create a signature of a string using a private key file. more >>

Contents

The code

$fp = fopen('private_key_file.pem', "r");
$priv_key = fread($fp, 8192);
fclose($fp);
$pkeyid = openssl_get_privatekey($priv_key, 'private_key_password_phrase');

$signature;
openssl_sign  ($string, $signature, $pkeyid);


Finally the variable $signature contains
the signature of the Strig $string.