/// <summary> /// Initialize the class /// <para>When using this constructor, you must call <see cref="Initialize(KeyParams)"/> before processing.</para> /// </summary> /// /// <param name="DisposeEngine">Dispose of digest engine when <see cref="Dispose()"/> on this class is called</param> public SHA512HMAC(bool DisposeEngine = true) { _shaDigest = new SHA512(); _shaHmac = new HMAC(_shaDigest, DisposeEngine); }
/// <summary> /// Initialize the class and working variables. /// <para>When this constructor is used, <see cref="Initialize(KeyParams)"/> is called automatically.</para> /// </summary> /// /// <param name="Key">HMAC Key; passed to HMAC Initialize() through constructor</param> /// <param name="DisposeEngine">Dispose of digest engine when <see cref="Dispose()"/> on this class is called</param> /// /// <exception cref="CryptoMacException">Thrown if a null Key is used</exception> public SHA512HMAC(byte[] Key, bool DisposeEngine = true) { if (Key == null) throw new CryptoMacException("SHA512HMAC:Ctor", "Key can not be null!", new ArgumentNullException()); _shaDigest = new SHA512(); _shaHmac = new HMAC(_shaDigest, Key, DisposeEngine); _isInitialized = true; }
private bool HashTest3() { byte[] data = new CSPRng().GetBytes(33033); byte[] hash1; byte[] hash2; using (StreamDigest dgt1 = new StreamDigest(new SHA512())) { dgt1.Initialize(new MemoryStream(data)); // run concurrent mode dgt1.IsConcurrent = true; hash1 = dgt1.ComputeHash(); } using (SHA512 dgt2 = new SHA512()) hash2 = dgt2.ComputeHash(data); return Compare.AreEqual(hash1, hash2); }