search

Home  >  Q&A  >  body text

javascript - js MD5 encryption of Chinese and python results are different.

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?

滿天的星座滿天的星座2757 days ago962

reply all(3)I'll reply

  • PHP中文网

    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>

    reply
    0
  • 阿神

    阿神2017-05-18 10:56:55

    AES encryption can be found randomly, you can refer to it

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-18 10:56:55

    It may be an encoding format problem. Check the encoding format of the characters received by your js

    reply
    0
  • Cancelreply