Javascript-js uses what method to encrypt the post data of Ajax to transmit PHP to decrypt

Source: Internet
Author: User
Tags decrypt asymmetric encryption
Because do not want to do in the Ajax post of the plaintext transmission, want to do JS to a JS object encrypted into a string or binary string transmission, but do not know how to encrypt, and this encrypted string needs to be decrypted on the PHP side, after decryption is preferably an array of PHP, Excuse me, do you have this kind of demand? You know how this is going to come true?

Reply content:

Because do not want to do in the Ajax post of the plaintext transmission, want to do JS to a JS object encrypted into a string or binary string transmission, but do not know how to encrypt, and this encrypted string needs to be decrypted on the PHP side, after decryption is preferably an array of PHP, Excuse me, do you have this kind of demand? You know how this is going to come true?

First of all, CRYPTO-JS can solve your problem. Choose a symmetric encryption algorithm (such as AES-256-CBC), on the PHP side with the aes+ password encryption, in the JS end with the aes+ password decryption-but it does not make much sense because your password is already in the JS code in clear.

So if you are aiming for non-plaintext transmission, it is recommended that you do asymmetric encryption from the transport layer, the simplest way is to switch the server protocol from HTTP to HTTPS.

You can use the asymmetric encryption algorithm to encrypt the public key in the browser and decrypt it with the private key on the server side. The JSENCRYPT project supports RSA encryption by simply openssl generating a key pair and then putting the public key on the page. PHP can be decrypted with the OpenSSL series function.

Encrypted and decrypted data is a string, if you want to get an array, you can create an object on the JS side, and then adjust and then JSON.stringify encrypt. The PHP solution is a JSON string, and the Json_decode function can be used to extract the array.

  • Related Article

    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.