HomePhpPHP RSA-SHA256 Signature - Create and verify sign by RSA public/private key PHP RSA-SHA256 Signature - Create and verify sign by RSA public/private key Makarablue July 12, 2022 0 - Generate RSA Signature by Privatekeypublic function generateSignature(String $content, String $privatekey) { $privatekey ="-----BEGIN RSA PRIVATE KEY-----\n$privatekey\n-----END RSA PRIVATE KEY-----"; $privateKeyId = openssl_pkey_get_private($privatekey); openssl_sign($content, $signature, $privateKeyId, 'RSA-SHA256'); $base64Str = base64_encode($signature); return $base64Str; }- Verify RSA Signature by Publickeypublic function verifySign(String $content, String $signature) { $publickey = your_publickey; $prepareKey ="-----BEGIN PUBLIC KEY-----\n".$publickey."\n-----END PUBLIC KEY-----"; $publicKeyId = openssl_pkey_get_public($prepareKey); kessLogger("Truemoney-verifySign signature: $signature ; content: $content"); $result = openssl_verify($content, base64_decode($signature), $publicKeyId, 'RSA-SHA256'); return $result == 1; } Tags Coding Configurations Php Newer Older