S
S
Sienore2017-11-29 11:28:40
PHP
Sienore, 2017-11-29 11:28:40

How to make encryption with private key and decryption with public key?

Good afternoon.
I am just starting to study this topic. It is required to implement a data encryption mechanism in PHP using OpenSSL.
In the example I found, the message is encrypted with the public key and decrypted with the private key. I need to do the opposite (encrypt the message with the user's private key, and decrypt it with the public key). Please let me know what changes need to be made.
PS This is necessary to implement an electronic signature in our system
slide_7.jpg

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
cicatrix, 2017-11-29
@cicatrix

The public key is not meant to decrypt messages. They can only encrypt.
You don't have the user's private key, because only the owner of the signature is supposed to have the private key (which is why it's private). If you have the user's private key, then your system (or rather, the user's system) is compromised.

R
Rsa97, 2017-11-29
@Rsa97

Do not use the mcrypt library, it is deprecated and will be moved to PECL starting with PHP version 7.2.0.
Use openssl, in your case openssl_private_encrypt() and openssl_public_decrypt()

A
Aryeh Leonid R., 2018-01-04
@aryeh

You are confusing signature/verification and encryption/decryption.
Signature/verification on your picture. The signature is made with a private key, and the verification is made with a public key.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question