This article mainly introduces the resolution of the encryption problem of OpenSSL in PHP, has a certain reference value, now share to everyone, the need for friends can refer to
Recent company projects need to use OpenSSL encryption and Java side for interface verification, and then test the environment to upgrade to PHP7 when the encryption will be error, and then the multi-faceted check finally found the reason:
PHP7 in the environment, openssl_get_privatekey
replace the methodopenssl_pkey_get_private
You need to convert the key, the window environment and the Linux environment of the key format is different (temporarily unsure whether it is the relationship of the operating system)
PHP's key verification needs to be added to the tail.
It's attached to the method.
To convert the secret key format:
function Transjavarsakeytophpopenssl ($content) { if ($content) { return trim (Chunk_split ($content, @, "\ n")) ; } return false; }
How to add and tail:
function Appendflags ($content, $isPublic = True) { if ($isPublic) { return "-----BEGIN public KEY-----\ n". $conte Nt. "\ n-----END public KEY-----\ n"; } else { return '-----BEGIN PRIVATE KEY-----\ n '. $content. "\ n-----END PRIVATE KEY-----\ n";} }
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!