public override void Dispose(bool disposing) { if (disposing) { _hHash?.Dispose(); _hKey?.Dispose(); _hProv?.Dispose(); } }
public void Dispose() { if (_currentIv is not null) { CryptographicOperations.ZeroMemory(_currentIv); } _hKey?.Dispose(); _hKey = null !; }
private SafeKeyHandle GetInitializedKey(ref SafeKeyHandle key, byte[] iv) { if (key == null || key.IsClosed || !this.CanStreamAcrossTopLevelCipherOperations || iv != null) { key?.Dispose(); try { using (var algorithm = this.symmetricAlgorithmProvider.OpenAlgorithm()) { key = BCryptGenerateSymmetricKey(algorithm, this.keyMaterial); } } catch (NTStatusException ex) { throw new ArgumentException(ex.Message, ex); } } return(key); }
protected override void Dispose(bool disposing) { if (disposing) { SafeKeyHandle hKey = _hKey; _hKey = null; if (hKey != null) { hKey.Dispose(); } SafeProvHandle hProvider = _hProvider; _hProvider = null; if (hProvider != null) { hProvider.Dispose(); } } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { SafeKeyHandle hKey = _hKey; _hKey = null; if (hKey != null) { hKey.Dispose(); } byte[] currentIv = _currentIv; _currentIv = null; if (currentIv != null) { Array.Clear(currentIv, 0, currentIv.Length); } } base.Dispose(disposing); }
public override bool TryFinalizeHashAndReset(Span <byte> destination, out int bytesWritten) { if (destination.Length < HashSizeInBytes) { bytesWritten = 0; return(false); } int hashSize = HashSizeInBytes; if (!Interop.Advapi32.CryptGetHashParam(_hHash, Interop.Advapi32.CryptHashProperty.HP_HASHVAL, destination, ref hashSize, 0)) { int hr = Interop.CPError.GetHRForLastWin32Error(); throw new CryptographicException(hr); } bytesWritten = hashSize; //reinitialize _hHash.Dispose(); _hKey.Dispose(); _hProv.Dispose(); SetKey(); return(true); }