将32为MD5摘要串转换为128位二进制字符串:
1 /// <summary> 2 /// 将字符串转成二进制 3 /// </summary> 4 /// <param name="s">源字符串</param> 5 /// <returns>二进制串</returns> 6 internal static string ConvertStringToBinary(string s) 7 { 8 if (s.IsNullOrWhiteSpace()) 9 { 10 throw new ArgumentNullException("源字符串为空", s); 11 } 12 if (s.Length != 32) 13 { 14 throw new ArgumentNullException("源字符串长度无效", s); 15 } 16 var bitBuilder = new StringBuilder(128); 17 for (var i = 0; i < s.Length; i += 2) 18 { 19 var tem = Convert.ToInt32(s.Substring(i, 2), 16); 20 bitBuilder.Append(Convert.ToString(tem, 2).PadLeft(8, '0')); 21 } 22 return bitBuilder.ToString(); 23 }