.Net常用普通加密方法

   /// <summary>
        /// 字符串Hash加密
      /// </summary>
        /// <param name="codeName">编码类型</param>
        /// <param name="sourceString">需要加密的字符串</param>
        /// <returns>MD5加密后字符串</returns>
        public static string HashString(string sourceString)
        {
            byte[] source = md5.ComputeHash(Encoding.GetEncoding("gb2312").GetBytes(sourceString));
            StringBuilder sBuilder = new StringBuilder();
            for (int i = 0; i < source.Length; i++)
            {
                sBuilder.Append(source[i].ToString("x"));
            }
            return sBuilder.ToString();
        }

posted @ 2011-08-10 10:06  xfyn  阅读(233)  评论(0编辑  收藏  举报