admin
管理员
管理员
  • UID1
  • 粉丝0
  • 关注0
  • 发帖数220
阅读:732回复:0

根据私钥文件pfx来进行RSA签名

楼主#
更多 发布于:2021-05-28 13:58
     $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;
 }
游客

返回顶部