Stephan-v
Stephan-v

Reputation: 20309

Encrypt and decrypt with the same private key?

I am working on some encryption and up until now I was under the assumption that you needed a public key to decrypt a value that has been encrypted by a private key.

That was until I saw openssl_private_encrypt() and openssl_private_decrypt() used with the same key.

I am a bit confused here. Don't you normally need the public key to decrypt a value again after is has been encrypted with a private key? Isn't this what the entire asymmetric encryption means?

It is hard to find reliable information about these kind of topics in a PHP context so I am hoping somebody could tell me a little bit more about this.

Thanks for reading.

Upvotes: 0

Views: 1106

Answers (1)

Blaatpraat
Blaatpraat

Reputation: 2849

If you encrypt something with a private key, to decrypt it with a public key, the only thing that is sure, is that you're the sender.

If you encrypt something with a public key, to decrypt it with a private key, you're sure that only the receiver can open it.

Best security is when you encrypt something with your private key, and the other persons public key, so that the other party can decrypt it with his private key and your public key.

So yes: you can encrypt and decrypt with a private key.

Upvotes: 2

Related Questions