When using python for MD5 encryption, the string needs to be encoded.
The code is as follows:
def md5(str):
str = str.encode('utf-8')
import hashlib
m = hashlib.md5()
m.update(str)
return m.hexdigest()
MD5 encryption for Chinese in js is:
string= MD5(string)
But the results are different. For example, the result of string= 'I am a test string' in python is: fd962c144eae1ac6912480fd4abd2d87
And the result in js is: 4fa9edf38bb340c273dc4c969ca680bb, so I want to know how these two languages compare to Chinese Can MD5 encryption be used to make the result consistent?
PHP中文网2017-05-18 10:56:55
<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://cdn.bootcss.com/blueimp-md5/1.1.0/js/md5.js"></script>
</head>
<body>
</body>
<script>
var str = md5("我是测试字符串");
console.log(str);
//fd962c144eae1ac6912480fd4abd2d87
</script>
</html>
漂亮男人2017-05-18 10:56:55
It may be an encoding format problem. Check the encoding format of the characters received by your js