/// <summary> /// MD5编码 /// </summary> /// <param name="encodeType">加密编码方法</param> /// <param name="dataStream">源字符串</param> /// <returns>编码后数据</returns> public static byte[] SecurityEncode(HashEncodeType encodeType, Stream dataStream) { switch (encodeType) { case HashEncodeType.Unknown: throw new NotImplementedException(); default: HashAlgorithm hashAlg = HashAlgorithm.Create(encodeType.ToString()); return(hashAlg.ComputeHash(dataStream)); } }
/// <summary> /// MD5编码 /// </summary> /// <param name="encodeType">加密编码方法</param> /// <param name="source">源字符串</param> /// <param name="encoding">编码前源字符串内容编码</param> /// <returns>编码后数据</returns> public static byte[] SecurityEncode(HashEncodeType encodeType, string source, Encoding encoding = null) { byte[] data = StringToBytes(source, encoding); return(SecurityEncode(encodeType, data)); }
/// <summary> /// 数据编码 /// </summary> /// <param name="encodeType">加密编码方法</param> /// <param name="dataStream">源字符串</param> /// <param name="lowcase">结果大小写:true-小写,false-大写,null-不处理</param> /// <returns>编码后目标字符串</returns> public static string SecurityEncodeToHex(HashEncodeType encodeType, Stream dataStream, bool?lowcase = null) { var result = SecurityEncode(encodeType, dataStream); return(BytesToHex(result, (bool)lowcase.HasValue)); }
/// <summary> /// 数据编码 /// </summary> /// <param name="encodeType">加密编码方法</param> /// <param name="dataStream">源字符串</param> /// <returns>编码后目标字符串</returns> public static string SecurityEncodeToBase64(HashEncodeType encodeType, Stream dataStream) { var result = SecurityEncode(encodeType, dataStream); return(Convert.ToBase64String(result)); }
/// <summary> /// 数据编码 /// </summary> /// <param name="encodeType">加密编码方法</param> /// <param name="source">源字符串</param> /// <param name="lowcase">结果大小写:true-小写,false-大写,null-不处理</param> /// <param name="encoding">编码前源字符串内容编码</param> /// <returns>编码后目标字符串</returns> public static string SecurityEncodeToHex(HashEncodeType encodeType, string source, bool?lowcase = null, Encoding encoding = null) { byte[] data = StringToBytes(source, encoding); return(SecurityEncodeToHex(encodeType, data, lowcase)); }