示例#1
0
        public static string Compute(HashType type, bool format, string data, string salt)
        {
            HashAlgorithm hash;
            string prefix;
            switch (type)
            {
                case HashType.MD5:
                    prefix = "MD5";
                    hash = new MD5Cng();
                    break;
                case HashType.SHA1:
                    prefix = "SHA1";
                    hash = new SHA1Cng();
                    break;
                case HashType.SHA256:
                    prefix = "SHA256";
                    hash = new SHA256Cng();
                    break;
                case HashType.SHA384:
                    prefix = "SHA384";
                    hash = new SHA384Cng();
                    break;
                case HashType.SHA512:
                    prefix = "SHA512";
                    hash = new SHA512Cng();
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(salt+data);
            byte[] hashed = hash.ComputeHash(inputBytes);
            return format ? $"{{{prefix}:{GetHashHex(hashed)}}}" : GetHashHex(hashed);
        }
示例#2
0
 public static string Sha384Base64(string text)
 {
     byte[] bytes = Encoding.UTF8.GetBytes(text);
     var hashstring = new SHA384Cng();
     byte[] hash = hashstring.ComputeHash(bytes);
     // this is to  make the hash url-safe for use in Azure table partition and row keys for example
     return Convert.ToBase64String(hash).Replace('/', '_');
 }
示例#3
0
		public override void SetUp ()
		{
			hash = new SHA384Cng ();
		}
		protected override void SetUp ()
		{
			hash = new SHA384Cng ();
		}