About using crypto-js AES to encrypt PHP backend decryption? Seek clarification and explanation


After looking at the relevant contents about encrypted login, it is really unsafe to log in without certificate and not by https method, and the value of POST can be seen in full.
I found some information about js encryption and php decryption, but it is still not very clear.
The general idea is that the foreground sends a request to the background to obtain a key, then the foreground encrypts it and transmits it to the back end for decryption.
(No certificate, just simple js encryption)
1. Is there a security risk when the foreground requests the key from the background, whether there is a cookie or a session?
2. It is true that many concepts are not clear enough to ask questions, but I hope Great Spirit can help sort them out.

http://skysbird.duichenmei.com/? p=306After seeing this code, my thinking became clearer.

These two codes were searched on the Internet again.
<script src=”http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/aes.js”></script>
<script src=”http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/md5.js”></script>
<script src=”http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/pad-zeropadding.js”></script>

<script> var key_hash = CryptoJS.MD5("Message");
 var key = CryptoJS.enc.Utf8.parse(key_hash);
 var iv  = CryptoJS.enc.Utf8.parse('1234567812345678');
 var encrypted = CryptoJS.AES.encrypt("Message", key, { iv: iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.ZeroPadding});
 Document.write("encode: "encrypted");


$text = "Message";
 $key = md5($text);  //key must be 16,32 bits long, here MD5 is a 32-bit key directly
 $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
 $decode = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $crypttext, MCRYPT_MODE_CBC, $iv);
 echo base64_encode($crypttext);
 echo "<br/>";
 echo $decode;
 echo "<br/>";

If it is corresponding, the encrypted value of js to php is equal to $crypttext, but mcrypt _ decrypts (mcrypt _ rijndael _ 128, $ key, $ crypttext, mcrypt _ mode _ CBC, $ iv); The $key in is the $text of md5. I can’t clear my name.
Ask for a simple and detailed explanation.

  1. Yes. If the key is transmitted in clear text, there will be hidden dangers of encryption. In addition, there is a more terrible example. It has been proved that some Chinese operators have directly changed the JS function used for encryption.
  2. In JS and PHP, the same key generation rule is used here: customize oneString, and then use its MD5 value as AES key. This will avoid problems such as key length complementation.