.NET ez 2012-08-22
方式一:效率較快!
/// <summary> /// 加密 /// </summary> /// <param name="original">字串</param> /// <returns>回傳加密結果</returns> public string Encrypt(string Str) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] bytes = md5.ComputeHash(Encoding.Default.GetBytes(Str)); return BitConverter.ToString(bytes).Replace("-", string.Empty); }
方式二:效率較慢,程式碼簡單!
/// <summary> /// 加密 /// </summary> /// <param name="Str">字串</param> /// <returns>回傳加密結果</returns> public string Encrypt(string Str) { return FormsAuthentication.HashPasswordForStoringInConfigFile(Str, "md5"); }
標籤: .NET