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 void ChangeKey(byte[] key) { // 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, 0, key.Length); key = _lazyHashProvider.FinalizeHashAndReset(); } HashProvider oldHashProvider = _hMacProvider; _hMacProvider = null; if (oldHashProvider != null) { oldHashProvider.Dispose(true); } _hMacProvider = HashProviderDispenser.CreateMacProvider(_hashAlgorithmId, key); ActualKey = key; }
public void ChangeKey(byte[] key) { HashProvider oldHashProvider = _hashProvider; _hashProvider = null; if (oldHashProvider != null) { oldHashProvider.Dispose(true); } _hashProvider = HashProviderDispenser.CreateMacProvider(_hashAlgorithmId, key); }