1 #region MD5 2 /// <summary> 3 /// 16位MD5加密 4 /// </summary> 5 /// <param name="password"></param> 6 /// <returns></returns> 7 public static string MD5Encrypt16(string strByMd5) 8 { 9 var md5 = new MD5CryptoServiceProvider(); 10 string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(strByMd5)), 4, 8); 11 t2 = t2.Replace("-", ""); 12 return t2; 13 } 14 15 /// <summary> 16 /// 32位MD5加密 17 /// </summary> 18 /// <param name="password"></param> 19 /// <returns></returns> 20 public static string MD5Encrypt32(string strByMd5) 21 { 22 string cl = strByMd5; 23 string pwd = ""; 24 the MD5 md5 = MD5.Create (); // instantiate a md5 of image 25 @ encrypted is a byte array type, the code selector to note here UTF8 / Unicode or the like 26 is byte [] S = md5. the ComputeHash (Encoding.UTF8.GetBytes (Cl)); 27 // by using a loop, the type byte array into a string of characters, the character is formatted conventionally obtained 28 for ( int I = 0 ; I <S .length; I ++ ) 29 { 30 // string obtained hexadecimal format type. After formatting character lowercase letters, uppercase if (X) after the character format is uppercase character 31 is pwd pwd = S + [I] .ToString ( " X- " ); 32 } 33 is return pwd; 34 is } 35 36 public static String MD5Encrypt64 ( String strByMd5) 37 [ { 38 is String Cl = strByMd5; 39 // String pwd = ""; 40 the MD5 md5 = MD5.Create (); // instantiate a pair of image md5 41 // encrypted is a byte array type, the code selector to note here UTF8 / Unicode or the like 42 is byte [] S = md5.ComputeHash (Encoding.UTF8.GetBytes (Cl)); 43 is return Convert.ToBase64String (S ); 44 is } 45 #endregion 46 is 47 #region the file MD5 process 48 /// <Summary> 49 /// file MD5 encryption stream 50 /// </ Summary> 51 is public static String MD5Stream (Stream Stream) 52 is { 53 is the MD5CryptoServiceProvider MD5 = new new the MD5CryptoServiceProvider (); 54 is md5.ComputeHash (Stream); 55 byte [] B = md5.Hash; 56 is md5.Clear (); 57 is the StringBuilder SB = new new the StringBuilder ( 32 ); 58 for ( int I = 0 ; I <b.length; I ++ ) 59 { 60 sb.append (B [I] .ToString ( " an X2 " )); 61 is } 62 is return sb.ToString (); 63 is } 64 65 /// <Summary> 66 /// the file MD5 encryption 67 /// </ Summary> 68 public static String MD5Stream ( String filePath) 69 { 70 the using(= The FileStream Stream File.Open (filePath, FileMode.Open)) 71 is { 72 return MD5Stream (Stream); 73 is } 74 } 75 76 #endregion 77 78 /// <Summary> 79 /// Gets MD5 value (to the word section array the MD5) 80 /// </ Summary> 81 /// <param name = "fileBytes"> </ param> 82 /// <Returns> </ Returns> 83 public static String GetMd5 ( byte [] fileBytes ) 84 { 85 var= The MD5 System.Security.Cryptography.MD5.Create () the ComputeHash (fileBytes);. 86 // The md5byte [] array to a string 87 var str_md5 = Convert.ToBase64String (the MD5); 88 return str_md5; 89 }