private byte[]? ChangeKeyImpl(ReadOnlySpan <byte> key) { byte[]? modifiedKey = null; // If _blockSize is -1 the key isn't going to be extractable by the object holder, // so there's no point in recalculating it in managed code. if (key.Length > _blockSize && _blockSize > 0) { // Perform RFC 2104, section 2 key adjustment. modifiedKey = _hashAlgorithmId switch { HashAlgorithmNames.SHA256 => SHA256.HashData(key), HashAlgorithmNames.SHA384 => SHA384.HashData(key), HashAlgorithmNames.SHA512 => SHA512.HashData(key), HashAlgorithmNames.SHA1 => SHA1.HashData(key), HashAlgorithmNames.MD5 when Helpers.HasMD5 => MD5.HashData(key), _ => throw new CryptographicException(SR.Format(SR.Cryptography_UnknownHashAlgorithm, _hashAlgorithmId)), }; } HashProvider?oldHashProvider = _hMacProvider; _hMacProvider = null !; oldHashProvider?.Dispose(true); _hMacProvider = HashProviderDispenser.CreateMacProvider(_hashAlgorithmId, key); return(modifiedKey); }
private byte[]? ChangeKeyImpl(ReadOnlySpan <byte> key) { byte[]? modifiedKey = null; // If _blockSize is -1 the key isn't going to be extractable by the object holder, // so there's no point in recalculating it in managed code. if (key.Length > _blockSize && _blockSize > 0) { // Perform RFC 2104, section 2 key adjustment. if (_lazyHashProvider == null) { _lazyHashProvider = HashProviderDispenser.CreateHashProvider(_hashAlgorithmId); } _lazyHashProvider.AppendHashData(key); modifiedKey = _lazyHashProvider.FinalizeHashAndReset(); } HashProvider?oldHashProvider = _hMacProvider; _hMacProvider = null !; oldHashProvider?.Dispose(true); _hMacProvider = HashProviderDispenser.CreateMacProvider(_hashAlgorithmId, key); return(modifiedKey); }
public override void Dispose(bool disposing) { if (disposing) { _hash1.Dispose(); _hash2.Dispose(); CryptographicOperations.ZeroMemory(_key); } }
/// <summary> /// Release all resources used by the current instance of the /// <see cref="IncrementalHash"/> class. /// </summary> public void Dispose() { _disposed = true; if (_hash != null) { _hash.Dispose(); _hash = null; } if (_hmac != null) { _hmac.Dispose(true); _hmac = null; } }
protected sealed override void Dispose(bool disposing) { _hashProvider.Dispose(disposing); base.Dispose(disposing); }
public void Dispose() => _provider.Dispose();