openssl encryption

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



HI,
I'm trying to encrypt and decrypt data in my PHP scripts using the
openssl API. However, while the encryption seems to work, I cannot
decrypt what I encrypted.

The keys I use have been produced the following way.

openssl req -x509 -nodes -days 365  -newkey rsa:4096 -keyout
example.key -out example.crt openssl x509 -in example.crt -pubkey
-noout > example.pub

I now try the following for encryption

$key = file_get_contents('example.pub');
$flag = openssl_public_encrypt($data,$encrypted,$key);

which seems to work fine.

Now, I try to decrypt as

$flag = openssl_private_decrypt($data,$decrypted,$key);
$key = file_get_contents('example.key');

This will result in

error:0407106B:rsa routines:func(113):reason(107)
error:04065072:rsa routines:func(101):reason(114)

Which according to 'openssl errstr' means
error:0407106B:rsa routines:RSA_padding_check_PKCS1_type_2:block type
is not 02 error:04065072:rsa routines:RSA_EAY_PRIVATE_DECRYPT:padding
check failed

Wht am I doing wrong?

I'm using PHP 4.3.9 which I cannot upgrade because I don't have full
control over the server. :(

I've also tried explicitly setting the padding type but to no avail.

Cheers,
Christian

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux