首先,16位加密与32位加密的区别,在于16位加密就是在32位加密的字符串中取中间16位,即是第9位到24位
比如现在有密码 sys
32位加密后的字符串就是 36BCBB801F5052739AF8220C6EA51434
16位加密后的字符串就是 1F5052739AF8220C
/// <summary> /// MD5_16位加密 /// </summary> public static string GetMD5_16(string value) { string md5Str = string.Empty; MD5 md5 = new MD5CryptoServiceProvider(); byte[] byData = Encoding.Default.GetBytes(value); byte[] result = md5.ComputeHash(byData); md5Str = BitConverter.ToString(result, 4, 8); md5Str = md5Str.Replace("-", ""); return md5Str; } /// <summary> /// MD5_32位加密 /// </summary> public static string GetMD5_32(string value) { string md5Str = string.Empty; MD5 md5 = new MD5CryptoServiceProvider(); byte[] byData = Encoding.Default.GetBytes(value); byte[] result = md5.ComputeHash(byData); md5Str = BitConverter.ToString(result); md5Str = md5Str.Replace("-", ""); return md5Str; } /// <summary> /// MD5_Base64加密 /// </summary> public static string GetMD5_Base64(string value) { string md5Str = string.Empty; MD5 md5 = new MD5CryptoServiceProvider(); byte[] byData = Encoding.Default.GetBytes(value); byte[] result = md5.ComputeHash(byData); md5Str = Convert.ToBase64String(result); return md5Str; } |
由于MD5是不可逆的,加密之后无法解密
所以在验证密码的时候只能用,将输入用同种加密方法加密后与与密码比较
另外MD5在破解过程中只能用穷举法