#56 - OpenSSL sign with PHP

Date: 2019-04-13 12:00 - PHP

Sample code how to sign a string with an RSA key in PHP.

<?php
// Generate the key
$privateKey = openssl_pkey_new(array(
    'private_key_bits' => 2048,
    'private_key_type' => OPENSSL_KEYTYPE_RSA));

// Sign the string
openssl_sign('my string to sign', $signature, $privateKey, 'SHA256');
echo base64_encode($signature);

Previous snippet | Next snippet