示例#1
0
 public override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _hHash?.Dispose();
         _hKey?.Dispose();
         _hProv?.Dispose();
     }
 }
示例#2
0
        public void Dispose()
        {
            if (_currentIv is not null)
            {
                CryptographicOperations.ZeroMemory(_currentIv);
            }

            _hKey?.Dispose();
            _hKey = null !;
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
            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);
            }