1 MD5 md5 = MD5.Create(); 2 var by = md5.ComputeHash(Encoding.Unicode.GetBytes( " 123456 " )); 3 StringBuilder sb = new StringBuilder(); 4 foreach (var item in by) 5 { 6 sb.Append(item.ToString( " x " )); 7 } 8 9 Console.WriteLine(sb); 10 StringBuilder sbb = new StringBuilder(); 11 var t = md5.TransformFinalBlock(by, 0 , by.Length / 2 ); 12 foreach (var item in t) 13 { 14 sbb.Append(item.ToString( " x " )); 15 } 16 Console.WriteLine(sbb); 17 18 Console.ReadLine();
1,返回指定长度的哈希值
2.代码:
Transformfinalblock
1 MD5 md5 = MD5.Create(); 2 var by = md5.ComputeHash(Encoding.Unicode.GetBytes( " 123456 " )); 3 StringBuilder sb = new StringBuilder(); 4 foreach (var item in by) 5 { 6 sb.Append(item.ToString( " x " )); 7 } 8 9 Console.WriteLine(sb); 10 StringBuilder sbb = new StringBuilder(); 11 var t = md5.TransformFinalBlock(by, 0 , by.Length / 2 ); 12 foreach (var item in t) 13 { 14 sbb.Append(item.ToString( " x " )); 15 } 16 Console.WriteLine(sbb); 17 18 Console.ReadLine();
参考: