rsa 报错 "error:04067072:rsa routines:RSA_EAY_PUBLIC_DECRYPT:padding check failed"

钧恩 发布于 2016/07/12 11:46
阅读 2K+
收藏 0
PHP
<?php 


$data = '{"SIGN":"cjcI6OjHzwFTEH4mGQfhMmIK1ZM0giXqQPi5QEQv65snfnQH+OflG6BtNoDn/9dDcarVDXzg56C3Z3nq4crI91HwIsLJdPSkm4+4wtpzSIgmz8vRqJFbwRG6bbmbRYeAkiqNj8NxZgsHp+dOLKE/ZU9r3uqWJ9qubQySZ70m6VM=","MERCHANT":"100010","CER":"YYYcu/XHd/S9zqH02AwGL7+lOQ0emkH54RXaS7ZtATof3Zj4DvXEekw1h5xsKz6g0kP/D/YFzwg6zLrqMe3zGGImDqW93/gvAAHamLT5iXSBSNB0DJ6dJ0GsPJQx9wpYemKcf6+HMWB6TvngyETcoEjiWBB67sThB+4GISJVbjs=","DATA":"x9kBkxXnZ2upPbfkd4J6fQFQcIDGi+d5aFVkYwRM3HDy5jQQKL2HuWbFv07BBR6btDHOKNdDIwKBAKL+mvfpw8sEL4tmAqL2f0iztzYRPt/5OhOP+P3R/R5sa0P8xfpRHEF/GRRCRGYUsSjM6/QR8P/dK9nebylAaYZRPhZwjgdIpjCFqJl2jnB8X43iONTPiO3AOt5Zfzn/C2+E1XEcahhSJI1Ue07vv6dB5vRixJZOKJ1DPOSibkS04NFyezqMRztcq/yf95o9asraNwSGkw=="}'; 
  $fp = fopen("./rsa_private_key.pem", "r"); //你的私钥文件路径
        $private_key = fread($fp, 8192);
        fclose($fp);
        $fp1 = fopen("./rsa_public_key.pem", "r"); //你的公钥文件路径
        $public_key = fread($fp1, 8192);
        fclose($fp1);
        //echo $private_key;
       
$pi_key =  openssl_pkey_get_private($private_key);//这个函数可用来判断私钥是否是可用的,可用返回资源id Resource id  
$pu_key = openssl_pkey_get_public($public_key);//这个函数可用来判断公钥是否是可用的  


  $json_arr = json_decode($data, true);
       $data1 = $json_arr['MERCHANT'] . $json_arr['CER'] . $json_arr['DATA'];


       $data2 = base64_decode($json_arr['SIGN']);  
         $res = openssl_verify($data1,$data2,$pu_key);
        var_dump($res);
        die;
$cer = "YYYcu/XHd/S9zqH02AwGL7+lOQ0emkH54RXaS7ZtATof3Zj4DvXEekw1h5xsKz6g0kP/D/YFzwg6zLrqMe3zGGImDqW93/gvAAHamLT5iXSBSNB0DJ6dJ0GsPJQx9wpYemKcf6+HMWB6TvngyETcoEjiWBB67sThB+4GISJVbjs=";
$result= openssl_private_decrypt($cer,$str, $pi_key);//私钥解密
 var_dump(openssl_error_string());
       var_dump($result);
       die;
加载中
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部