首页 > Web开发 > 详细

php 证书加密 和证书解密方法

时间:2018-08-27 10:15:13      阅读:170      评论:0      收藏:0      [点我收藏+]

//证书加密需要传的参数  字符串  证书地址  证书密码!

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;
}

php 证书加密 和证书解密方法

原文:https://www.cnblogs.com/oy123/p/9540344.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!