PHP OpenSSL encryption problem sorting, phpopenssl

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.