You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
payment/app/Helper/Efps/Signer.php

32 lines
962 B
PHP

<?php
namespace App\Helper\Efps;
class Signer
{
public static function sign($content, $privateKey)
{
$privateKey = "-----BEGIN RSA PRIVATE KEY-----\n" .
wordwrap($privateKey, 64, "\n", true) .
"\n-----END RSA PRIVATE KEY-----";
$key = openssl_get_privatekey($privateKey);
// openssl_private_encrypt($content, $signature, $privateKey, OPENSSL_PKCS1_PADDING);
openssl_sign($content, $signature, $key, OPENSSL_ALGO_SHA256);
openssl_free_key($key);
return base64_encode($signature);
}
public function verify($content, $sign, $publicKey){
$publicKey = "-----BEGIN PUBLIC KEY-----\n" .
wordwrap($publicKey, 64, "\n", true) .
"\n-----END PUBLIC KEY-----";
$key = openssl_get_publickey($publicKey);
$ok = openssl_verify($content, base64_decode($sign), $key, 'SHA256');
openssl_free_key($key);
return $ok;
}
}