//证书加密需要传的参数 字符串 证书地址 证书密码!
function sign($data,$pfxpath,$pfxpwd) {
$certs = array();
openssl_pkcs12_read(file_get_contents($pfxpath), $certs, $pfxpwd); // 其中password为你的证书密码
if (!$certs) {
return;
}
$signature = ‘‘;
openssl_sign($data, $signature, $certs[‘pkey‘]);
return base64_encode($signature);
}
//证书解密字符串 ,编码加密的字符串
function verify($data, $signature) {
$certs = array();
openssl_pkcs12_read(file_get_contents(‘./test.pfx‘), $certs, ‘hzsmk‘);
if(!$certs) {
return;
}
$result = openssl_verify($data, base64_decode($signature), $certs[‘cert‘]); // openssl_verify验签成功返回1,失败0,错误返回-1
return $result;
}
原文地址:https://www.cnblogs.com/oy123/p/9540344.html
时间: 2024-10-28 16:15:19