Esempio n. 1
0
 [System.Security.SecuritySafeCritical] // overrides public transparent member
 protected override void Dispose(bool disposing)
 {
     if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
     {
         _safeHashHandle.Dispose();
     }
     // call the base class's Dispose
     base.Dispose(disposing);
 }
Esempio n. 2
0
 public override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _hHash?.Dispose();
         _hProv?.Dispose();
     }
 }
            private void DestroyHash()
            {
                SafeHashHandle hHash = _hHash;

                _hHash = null;
                if (hHash != null)
                {
                    hHash.Dispose();
                }
            }
Esempio n. 4
0
            public override bool TryFinalizeHashAndReset(Span<byte> destination, out int bytesWritten)
            {
                int hashSize = HashSizeInBytes;
                if (!Interop.Advapi32.CryptGetHashParam(_hHash, Interop.Advapi32.CryptHashProperty.HP_HASHVAL, destination, ref hashSize, 0))
                {
                    int hr = Marshal.GetHRForLastWin32Error();
                    throw new CryptographicException(hr);
                }
                bytesWritten = hashSize;

                //reinitialize
                _hHash.Dispose();
                if (!Interop.Advapi32.CryptCreateHash(_hProv, _calgHash, SafeKeyHandle.InvalidHandle, (int)Interop.Advapi32.CryptCreateHashFlags.None, out _hHash))
                {
                    int hr = Marshal.GetHRForLastWin32Error();
                    throw new CryptographicException(hr);
                }
                _hHash.SetParent(_hProv);
                return true;
            }
Esempio n. 5
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);
            }