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.