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; }
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 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!