czLukasss
czLukasss

Reputation: 750

OpenSSL encrypt is ok, but decrypt is false

first, im sorry for my bad English.

Im forced to use OpenSSL and im testing it now.

I have public key:

$key = "{key}"; 
$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----";

When i use:

$secret = "test";
$test = openssl_public_encrypt($secret, $encrypted, $key);

... everything is ok, in $test is true - so encrypting is ok.

But now, i want decrypt it back, so i use:

$ok = openssl_public_decrypt($encrypted, $vys, $key);

...and on this place, the $ok variable contains false :( How it is possible?

Thanks very much to all!

Upvotes: 1

Views: 620

Answers (1)

Chiara Hsieh
Chiara Hsieh

Reputation: 3393

You should decrypt with openssl_private_decrypt()
And you need to provide private key as argument.
Try to read more about public key encryption and openssl_public_encrypt

Upvotes: 5

Related Questions