阅读:911回复:0
根据私钥文件pfx来进行RSA签名
$signStr = trim($signStr, '&');
$pfxpath=dirname(__FILE__).'/cert/plyx.pfx'; $pfxpassword='plyx12'; $sign = sign_encrypt(array('data' => $signStr),$pfxpath,$pfxpassword); $myParams['sign'] = trim($sign['check']); function sign_encrypt($input,$pfxpath,$pfxpassword) { $return = array('success' => 0, 'msg' => '', 'check' => ''); $pkcs12 = file_get_contents($pfxpath); //私钥 if (openssl_pkcs12_read($pkcs12, $certs, $pfxpassword)) { $privateKey = $certs['pkey']; $publicKey = $certs['cert']; $signedMsg = ""; if (openssl_sign($input['data'], $signedMsg, $privateKey, OPENSSL_ALGO_SHA1)) { $return['success'] = 1; $return['check'] = base64_encode($signedMsg); $return['msg'] = base64_encode($input['data']); } } return $return; } |
|