PHP OpenSSL encryption problem sorting, phpopenssl
Recently, in our project, we need to use OpenSSL encryption and java to perform Interface Verification. When the test environment is upgraded to PHP7, an error occurs during encryption. Then, we finally find the cause for the following checks:
In the PHP7 environment, replace openssl_get_privatekey with openssl_pkey_get_private.
You need to convert the key. The key format in the window environment is different from that in the Linux environment (it is not clear whether the key is related to the operating system)
The header and tail must be added for PHP key verification.
Attach the method here
How to convert the key format:
Function transJavaRsaKeyToPhpOpenSSL ($ content) {if ($ content) {return trim (chunk_split ($ content, 64, "\ n");} return false ;}
Method of adding the header and tail:
Function appendFlags ($ content, $ isPublic = true) {if ($ isPublic) {return "----- begin public key ----- \ n ". $ content. "\ n ----- end public key ----- \ n";} else {return "----- begin private key ----- \ n ". $ content. "\ n ----- end private key ----- \ n ";}}
The above is a small experience in OPENSSL encryption. If you have any questions, leave a message below to discuss them.