public string HMACSign(byte[] data, string key, SigningAlgorithm algorithmName) { if (String.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", "Please specify a Secret Signing Key."); } if (data == null || data.Length == 0) { throw new ArgumentNullException("data", "Please specify data to sign."); } KeyedHashAlgorithm algorithm = CreateKeyedHashAlgorithm(algorithmName); if (null == algorithm) { throw new InvalidOperationException("Please specify a KeyedHashAlgorithm to use."); } try { algorithm.Key = Encoding.UTF8.GetBytes(key); byte[] bytes = algorithm.ComputeHash(data); return(Convert.ToBase64String(bytes)); } finally { algorithm.Dispose(); } }
public byte[] HMACSignBinary(byte[] data, byte[] key, SigningAlgorithm algorithmName) { if (key == null || key.Length == 0) { throw new ArgumentNullException("key", "Please specify a Secret Signing Key."); } if (data == null || data.Length == 0) { throw new ArgumentNullException("data", "Please specify data to sign."); } KeyedHashAlgorithm algorithm = CreateKeyedHashAlgorithm(algorithmName); if (null == algorithm) { throw new InvalidOperationException("Please specify a KeyedHashAlgorithm to use."); } try { algorithm.Key = key; byte[] bytes = algorithm.ComputeHash(data); return(bytes); } finally { algorithm.Dispose(); } }
/// <summary> /// Closes the stream, clearing memory and disposing of the HMAC algorithm. /// </summary> //public override void Close() protected override void Dispose(bool disposing) { base.Dispose(disposing); Security.Clear(_saltBuffer); Security.Clear(_digest); Security.Clear(_digestT1); //_hmacAlgorithm.Clear(); _hmacAlgorithm.Dispose(); }
/// <summary> /// Performs the actual job of disposing the object. /// </summary> /// <param name="disposing"> /// Passes the information whether this method is called by <see cref="Dispose()"/> (explicitly or /// implicitly at the end of a <c>using</c> statement), or by the <see cref="M:~Hasher"/>. /// </param> /// <remarks> /// If the method is called with <paramref name="disposing"/><c>==true</c>, i.e. from <see cref="Dispose()"/>, /// it will try to release all managed resources (usually aggregated objects which implement <see cref="IDisposable"/> as well) /// and then it will release all unmanaged resources if any. If the parameter is <c>false</c> then /// the method will only try to release the unmanaged resources. /// </remarks> protected virtual void Dispose(bool disposing) { // if it is disposed or in a process of disposing - return. if (Interlocked.Exchange(ref _disposed, 1) != 0) { return; } if (disposing) { _hashAlgorithm.Dispose(); } }
/// <summary> /// Disposes of internal components. /// </summary> /// <param name="disposing">true, if called from Dispose(), false, if invoked inside a finalizer.</param> protected override void Dispose(bool disposing) { if (!_disposed) { _disposed = true; if (disposing) { if (_keyedHash != null) { _keyedHash.Dispose(); _keyedHash = null; } } } }
/// <summary> /// Disposes of internal components. /// </summary> /// <param name="disposing">true, if called from Dispose(), false, if invoked inside a finalizer.</param> protected override void Dispose(bool disposing) { if (!_disposed) { _disposed = true; CryptoProviderCache?.TryRemove(this); if (disposing) { if (_keyedHash != null) { _keyedHash.Dispose(); _keyedHash = null; } } } }
public override void Dispose() { algorithm.Dispose(); }
public void Dispose() { _ct.Dispose(); _mac.Dispose(); }
public void Dispose() { _realAlgorithm?.Dispose(); }
public void Dispose() { _keyedHash.Dispose(); }
public void Dispose() { _hmac.Dispose(); }