Home >Backend Development >PHP Tutorial >Solving the encryption problem of OpenSSL in PHP
This article mainly introduces the solution to the encryption problem of OpenSSL in PHP. It has a certain reference value. Now I share it with you. Friends in need can refer to it.
There is a need for it in recent company projects. Go to the encryption and java side of OpenSSL to perform interface verification. When the test environment is upgraded to PHP7, an encryption error will occur. Later, after multiple inspections, the cause was finally found:
# in the PHP7 environment. ##openssl_get_privatekeyThe method is changed to
openssl_pkey_get_private
Method to convert the secret key format:
function transJavaRsaKeyToPhpOpenSSL($content) { if ($content) { return trim(chunk_split($content, 64, "\n")); } return false; }Method to add 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 this article The entire content, I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website! Related recommendations:
The above is the detailed content of Solving the encryption problem of OpenSSL in PHP. For more information, please follow other related articles on the PHP Chinese website!