user4817873
user4817873

Reputation:

Sign digital signature using PHP

How to sign digital signature using PHP?

Upvotes: 3

Views: 2144

Answers (2)

Vitalicus
Vitalicus

Reputation: 1389

You can use tcpdf class for this. https://tcpdf.org/examples/example_001/

Upvotes: 0

AlliterativeAlice
AlliterativeAlice

Reputation: 12577

Right from 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 a private key you can skip generating one and just use it as the $private_key_pem parameter in openssl_sign() directly.

Upvotes: 1

Related Questions