Home >Backend Development >PHP Tutorial >Detailed explanation of php rsa encryption and decryption_PHP tutorial
1. The first step in encryption and decryption is to generate a public key and private key pair. The content encrypted by the private key can be decrypted by the public key (reverse You can also come over)
Download the open source RSA key generation tool openssl (usually Linux systems come with this program), unzip it to a separate folder, enter the bin directory, and execute the following command:
The code is as follows:
The first command generates the original RSA private key file rsa_private_key.pem, the second command converts the original RSA private key to pkcs8 format, and the third command generates the RSA public key rsa_public_key.pem
It can be seen from the above that the corresponding public key can be generated through the private key, so we use the private key private_key.pem on the server side, and the public key is distributed to front-ends such as android and ios
2. Use the generated public key and private key to encrypt and decrypt in php, and directly upload the code
The code is as follows:
FAQs about PHP’s RSA configuration:
●Usage of 3 DLL files in the openssl folder in the code example of PHP development language
1. If your system is a windows system and there are no libeay32.dll and ssleay32.dll files in the system32 file directory
Then you need to copy these two files to the system32 file directory.
2. If there is no php_openssl.dll in your php installation directory (phpext)
Then please put php_openssl.dll in this folder
Friends who like encryption and decryption must read this article carefully and benefit a lot. . .