使用RSA解密问题


Decryption problem using RSA

我有以下步骤来执行解密

    base64解码响应
  1. 使用RSA1024公钥解密前128字节。密钥采用base64编码的X509格式,并使用PKCS1填充。

我的代码是这样的:

$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);

我无法在$decrypted变量中得到任何东西。如果我尝试base64解码公钥之前使用它,我得到的错误不是一个有效的公钥。我错过了什么或做错了,以实现上述两个步骤?

查看openssl_pkey_get_public:

http://www.php.net/manual/en/function.openssl-pkey-get-public.php # 101513

PKCS1填充似乎给该函数带来了问题。

这实际上是我如何得到响应的问题。通过在base64解码之前做urldecode,我能够得到适当的结果。

$decodedString = $this->base64UrlDecode(urldecode($string));