1

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?

1
  • is it something related to creation of that .key file? Commented Sep 19, 2011 at 11:38

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

it works only for 2048 bits. I need a solution for 1024 bits :(
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.