doushi9856 2011-09-19 10:32
浏览 242
已采纳

使用RSA的解密问题

I have following steps to perform for decryption

  1. base64 decode the response
  2. Decrypt the first 128 bytes with the RSA1024 public key. Key is in base64 encoded X509 format with PKCS1 padding.

My code looks like this:

$decodedString = $this->base64UrlDecode($string); //does proper url decoding                
$publicKey = file_get_contents("public.key",true); 
$pub_key = openssl_get_publickey($publicKey);   
openssl_public_decrypt($decodedString,$decrypted,$pub_key,OPENSSL_PKCS1_PADDING);
var_dump($decrypted);

I am not able to get anything in $decrypted variable. If I try to base64 decode public key before using it, I am getting error of not a valid public key. What I am missing or doing wrong to achieve mentioned 2 steps?

  • 写回答

2条回答 默认 最新

  • duanbipu1720 2011-10-07 09:29
    关注

    It was actually a problem with how I was getting response. By doing urldecode before base64 decoding I am able to get proper results.

    $decodedString = $this->base64UrlDecode(urldecode($string));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?