#region 用SHA1加密字符串 /// <summary> /// 用SHA1加密字符串 /// </summary> /// <param name="source">要扩展的对象</param> /// <param name="isReplace">是否替换掉加密后的字符串中的"-"字符</param> /// <param name="isToLower">是否把加密后的字符串转小写</param> /// <returns></returns> public static string SHA1Encrypt(this string source, bool isReplace = true, bool isToLower = false) { SHA1 sha1 = SHA1.Create(); byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(source)); string shaStr = BitConverter.ToString(hash); if (isReplace) { shaStr = shaStr.Replace("-", ""); } if (isToLower) { shaStr = shaStr.ToLower(); } return shaStr; } #endregion var str = $"{DateTime.Today.Year}-66921d8e-1159-474b-8e8e-faewr7dc0f14-{DateTime.Today.Month}{DateTime.Today.Day}"; var strSha1 = BitConverter.ToString(System.Security.Cryptography.SHA1.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes(str))).Replace("-", "").ToLower();