protected override void HashCore(byte[] rgb, int ibStart, int cbSize) { IntPtr intPtr; if (this.m_hashValue != null) { throw new ArgumentException("HashValue must be null."); } if (!HMACSHA256FISMACompliant.NativeMethods.CryptCreateHash(this.m_hProv, 32777, this.m_hKey, 0, out intPtr)) { this.ProcessPInvokeFailure("CryptCreateHash"); } HMACSHA256FISMACompliant.HMAC_INFO hMACINFO = new HMACSHA256FISMACompliant.HMAC_INFO() { HashAlgid = 32780 }; if (!HMACSHA256FISMACompliant.NativeMethods.CryptSetHashParam(intPtr, 5, hMACINFO, 0)) { this.ProcessPInvokeFailure("CryptSetHashParam"); } byte[] numArray = rgb; if (ibStart > 0) { numArray = new byte[cbSize]; Array.Copy(rgb, ibStart, numArray, 0, cbSize); } if (!HMACSHA256FISMACompliant.NativeMethods.CryptHashData(intPtr, numArray, cbSize, 0)) { this.ProcessPInvokeFailure("CryptHashData"); } this.m_hashValue = new byte[32]; int length = (int)this.m_hashValue.Length; if (!HMACSHA256FISMACompliant.NativeMethods.CryptGetHashParam(intPtr, 2, this.m_hashValue, ref length, 0)) { this.ProcessPInvokeFailure("CryptGetHashParam"); } if (!HMACSHA256FISMACompliant.NativeMethods.CryptDestroyHash(intPtr)) { this.ProcessPInvokeFailure("CryptDestroyHash"); } }
public static extern bool CryptSetHashParam(IntPtr hHash, uint dwParam, [In] HMACSHA256FISMACompliant.HMAC_INFO hmacInfo, uint dwFlags);