/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.HMACSHA256" /> class with the specified key data.</summary>
 /// <param name="key">The secret key for <see cref="T:System.Security.Cryptography.HMACSHA256" /> encryption. The key can be any length. However, the recommended size is 64 bytes. If the key is more than 64 bytes long, it is hashed (using SHA-256) to derive a 64-byte key. If it is less than 64 bytes long, it is padded to 64 bytes. </param>
 /// <exception cref="T:System.ArgumentNullException">The <paramref name="key" /> parameter is <see langword="null" />. </exception>
 // Token: 0x060021C3 RID: 8643 RVA: 0x00077818 File Offset: 0x00075A18
 public HMACSHA256(byte[] key)
 {
     this.m_hashName    = "SHA256";
     this.m_hash1       = HMAC.GetHashAlgorithmWithFipsFallback(() => new SHA256Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA256CryptoServiceProvider"));
     this.m_hash2       = HMAC.GetHashAlgorithmWithFipsFallback(() => new SHA256Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA256CryptoServiceProvider"));
     this.HashSizeValue = 256;
     base.InitializeKey(key);
 }
Exemplo n.º 2
0
        /// <summary>使用指定的密钥数据初始化 <see cref="T:System.Security.Cryptography.HMACSHA256" /> 类的新实例。</summary>
        /// <param name="key">
        /// <see cref="T:System.Security.Cryptography.HMACSHA256" /> 加密的机密密钥。该密钥可以是任意长度。但是建议的大小为 64 个字节。如果键的长度超过 64 个字节,将对其进行哈希运算(使用 SHA-256)以派生出一个 64 字节的密钥。如果少于 64 个字节,就填充到 64 个字节。</param>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="key" /> 参数为 null。</exception>
        public HMACSHA256(byte[] key)
        {
            this.m_hashName = "SHA256";
            Func <HashAlgorithm> func1 = (Func <HashAlgorithm>)(() => (HashAlgorithm) new SHA256Managed());
            Func <HashAlgorithm> createStandardHashAlgorithmCallback1;

            this.m_hash1 = HMAC.GetHashAlgorithmWithFipsFallback(createStandardHashAlgorithmCallback1, (Func <HashAlgorithm>)(() => HashAlgorithm.Create("System.Security.Cryptography.SHA256CryptoServiceProvider")));
            Func <HashAlgorithm> func2 = (Func <HashAlgorithm>)(() => (HashAlgorithm) new SHA256Managed());
            Func <HashAlgorithm> createStandardHashAlgorithmCallback2;

            this.m_hash2       = HMAC.GetHashAlgorithmWithFipsFallback(createStandardHashAlgorithmCallback2, (Func <HashAlgorithm>)(() => HashAlgorithm.Create("System.Security.Cryptography.SHA256CryptoServiceProvider")));
            this.HashSizeValue = 256;
            this.InitializeKey(key);
        }