使用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?

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

See this comment for openssl_pkey_get_public:

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

PKCS1 padding poses a problem to that function, it seems.