The python md5 and base64 encryption

Recently a company and to carry out docking system, the other using C # gives such an encryption function:

1
2
3
4
5
6
7
8
public static string (string str)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] temp = System.Text.Encoding.UTF8.GetBytes(str);
byte[] MD5 = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(str));
string result = Convert.ToBase64String(MD5, 0, MD5.Length);//Base64
return result;
}

First byte string into a form, then its MD5 encryption, and finally BASE64 encryption. In the first note in Chinese Python2 code is very easy to go wrong, it first becomes unicode string form, and then were subjected to encode:

Large column   in python md5 and base64 encryption ">
1
2
3
4
5
6
7
8
9
10
11
12
Import hashlib 
Import Base64
DEF getCode (unicxml) : '' 'generates a check code according to the stitched XML XML needs Unicode ' '' TEMP = unicxml.encode ( "UTF-. 8" ) MD5 = hashlib.md5 () MD5. Update (TEMP) md5str md5.digest = () # 16 bit b64str = base64.b64encode (md5str) return b64str









From the process point of view algorithm it should be the same, but I do not know why we found base64 code but still can not be verified. After the last resort built .net C # found in the development environment is a 16-bit md5 encryption, so do not use 32-bit ciphertext generating md5.hexdigest in python.

Guess you like

Origin www.cnblogs.com/dajunjun/p/11698815.html