Akamai.Utils.ExtensionMethods.ComputeKeyedHash C# (CSharp) Метод

ComputeKeyedHash() публичный статический Метод

Computes the HMAC hash of a given byte[]. This is a wrapper over the Mac crypto functions.
public static ComputeKeyedHash ( this data, string key, KeyedHashAlgorithm hashType = KeyedHashAlgorithm.HMACSHA256 ) : byte[]
data this byte[] of content to hash
key string secret key to salt the hash. This is assumed to be UTF-8 encoded
hashType System.Security.Cryptography.KeyedHashAlgorithm determines which alogirthm to use. The recommendation is to use HMAC-SHA256
Результат byte[]
        public static byte[] ComputeKeyedHash(this byte[] data, string key, KeyedHashAlgorithm hashType = KeyedHashAlgorithm.HMACSHA256)
        {
            if (data == null) return null;

            if (string.IsNullOrEmpty(key))
                throw new ArgumentNullException("key");

            using (var algorithm = HMAC.Create(hashType.ToString()))
            {
                algorithm.Key = key.ToByteArray();
                return algorithm.ComputeHash(data);
            }
        }

Usage Example

Пример #1
0
 public void ComputeKeyedHashNullException()
 {
     ExtensionMethods.ComputeKeyedHash("value".ToByteArray(), null);
 }
All Usage Examples Of Akamai.Utils.ExtensionMethods::ComputeKeyedHash