Esempio n. 1
0
		protected override void Dispose(bool disposing)
		{
			base.Dispose(disposing);

			if (hmac != null)
				hmac.Dispose();
		}
Esempio n. 2
0
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (_hmac != null)
                    {
                        _hmac.Dispose();
                        _hmac = null;
                    }

                    if (_buffer != null)
                    {
                        Array.Clear(_buffer, 0, _buffer.Length);
                    }
                    if (_password != null)
                    {
                        Array.Clear(_password, 0, _password.Length);
                    }
                    if (_salt != null)
                    {
                        Array.Clear(_salt, 0, _salt.Length);
                    }
                }
                base.Dispose(disposing);
            }
Esempio n. 3
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                if (_containerKey != null)
                {
                    _containerKey.Dispose();
                }

                if (_kdf != null)
                {
                    _kdf.Dispose();
                }

                if (_hmac != null)
                {
                    _hmac.Dispose();
                }
            }

            _disposed = true;
        }
Esempio n. 4
0
        /// <summary>
        /// Dispose of all contained resources.
        /// </summary>
        public void Dispose()
        {
            if (m_decryptionBulkAlgorithm != null)
            {
                m_decryptionBulkAlgorithm.Dispose();
                m_decryptionBulkAlgorithm = null;
            }

            if (m_encryptionBulkAlgorithm != null)
            {
                m_encryptionBulkAlgorithm.Dispose();
                m_encryptionBulkAlgorithm = null;
            }

            if (m_decryptionHMAC != null)
            {
                m_decryptionHMAC.Dispose();
                m_decryptionHMAC = null;
            }

            if (m_encryptionHMAC != null)
            {
                m_encryptionHMAC.Dispose();
                m_encryptionHMAC = null;
            }

            if (PRF != null)
            {
                PRF.Dispose();
                PRF = null;
            }
        }
 public void Dispose()
 {
     if (_hmac != null)
     {
         _hmac.Dispose();
         _hmac = null;
     }
 }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hmac"></param>
        /// <param name="stream">待加密的流</param>
        /// <returns></returns>
        private static string GetHMacSha(HMAC hmac, Stream stream)
        {
            byte[] hashmessage = hmac.ComputeHash(stream);
            string res         = hashmessage.ConvertToBase64();

            hmac.Dispose();
            return(res);
        }
 public void Dispose()
 {
     if (!disposed)
     {
         hmac.Dispose();
         hmac     = null;
         disposed = true;
     }
 }
Esempio n. 8
0
 private void DisposeHmac()
 {
     if (_Hmac != null)
     {
         Array.Clear(_Hmac.Key, 0, _Hmac.Key.Length);
         _Hmac.Dispose();
         _Hmac = null;
     }
 }
Esempio n. 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hmac"></param>
        /// <param name="str">待价密的字符串</param>
        /// <param name="encoding">编码格式,默认UTF-8</param>
        /// <returns></returns>
        private static string GetHMacSha(HMAC hmac, string str, Encoding encoding)
        {
            byte[] messageBytes = encoding.GetBytes(str);
            byte[] hashmessage  = hmac.ComputeHash(messageBytes);
            string res          = hashmessage.ConvertToBase64();

            hmac.Dispose();
            return(res);
        }
Esempio n. 10
0
        public static void VerifyGetCurrentHash_HMAC(HMAC referenceAlgorithm, HashAlgorithmName hashAlgorithm)
        {
            referenceAlgorithm.Dispose();

            using (IncrementalHash single = IncrementalHash.CreateHMAC(hashAlgorithm, s_hmacKey))
                using (IncrementalHash accumulated = IncrementalHash.CreateHMAC(hashAlgorithm, s_hmacKey))
                {
                    VerifyGetCurrentHash(single, accumulated);
                }
        }
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            _secretHmac.Dispose();
            _tagHmac.Dispose();
            _prf.Dispose();
            _disposed = true;
        }
Esempio n. 12
0
        public void Dispose()
        {
            if (!isDisposed)
            {
                if (signer != null)
                {
                    signer.Dispose();
                    signer = null;
                }

                isDisposed = true;
            }
        }
        public static void Dispose_HMAC_ThrowsException(HMAC referenceAlgorithm, HashAlgorithmName hashAlgorithm)
        {
            referenceAlgorithm.Dispose();
            var incrementalHash = IncrementalHash.CreateHMAC(hashAlgorithm, s_hmacKey);

            incrementalHash.Dispose();

            Assert.Throws <ObjectDisposedException>(() => incrementalHash.AppendData(new byte[1]));
            Assert.Throws <ObjectDisposedException>(() => incrementalHash.AppendData(new ReadOnlySpan <byte>(new byte[1])));

            Assert.Throws <ObjectDisposedException>(() => incrementalHash.GetHashAndReset());
            Assert.Throws <ObjectDisposedException>(() => incrementalHash.TryGetHashAndReset(new byte[1], out int _));
        }
Esempio n. 14
0
        public static HMAC Create(string algorithmName, byte[] key)
        {
            HMAC hmac = HMAC.Create(algorithmName);

            try
            {
                hmac.Key = key;
                return(hmac);
            }
            catch {
                hmac.Dispose();
                throw;
            }
        }
Esempio n. 15
0
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                _hmac?.Dispose();
            }

            _disposed = true;
        }
Esempio n. 16
0
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                // ReSharper disable once InconsistentlySynchronizedField
                _hmac?.Dispose();
            }

            _disposed = true;
        }
Esempio n. 17
0
        /// <summary>
        /// Creates an HMAC-SHA algorithm with the specified name and key.
        /// </summary>
        /// <param name="algorithmName">A name from the available choices in the static const members of this class.</param>
        /// <param name="key">The secret key used as the HMAC.</param>
        /// <returns>The HMAC algorithm instance.</returns>
        internal static HMAC Create(string algorithmName, byte[] key)
        {
            Requires.NotNullOrEmpty(algorithmName, "algorithmName");
            Requires.NotNull(key, "key");

            HMAC hmac = HMAC.Create(algorithmName);

            try {
                hmac.Key = key;
                return(hmac);
            } catch {
                hmac.Dispose();
                throw;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Dispose of all contained resources.
        /// </summary>
        public void Dispose()
        {
            if (m_decryptionBulkAlgorithm != null)
            {
#if NET40
                m_decryptionBulkAlgorithm.Dispose();
#else
                m_decryptionBulkAlgorithm.Clear();
#endif
                m_decryptionBulkAlgorithm = null;
            }

            if (m_encryptionBulkAlgorithm != null)
            {
#if NET40
                m_encryptionBulkAlgorithm.Dispose();
#else
                m_encryptionBulkAlgorithm.Clear();
#endif
                m_encryptionBulkAlgorithm = null;
            }

            if (m_decryptionHMAC != null)
            {
#if NET40
                m_decryptionHMAC.Dispose();
#else
                m_decryptionHMAC.Clear();
#endif
                m_decryptionHMAC = null;
            }

            if (m_encryptionHMAC != null)
            {
#if NET40
                m_encryptionHMAC.Dispose();
#else
                m_encryptionHMAC.Clear();
#endif
                m_encryptionHMAC = null;
            }

            if (PRF != null)
            {
                PRF.Dispose();
                PRF = null;
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (_containerKey != null)
                    _containerKey.Dispose();

                if (_kdf != null)
                    _kdf.Dispose();

                if (_hmac != null)
                    _hmac.Dispose();

                disposed = true;
            }
        }
        public void Dispose()
        {
            if (rawHmac != null)
            {
                //overwrite memory address
                for (int i = 0; i < rawHmac.Length; i++)
                {
                    rawHmac[i] = 0;
                }

                //release memory now
                rawHmac = null;
            }
            mac?.Dispose();
            mac = null;
        }
Esempio n. 21
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (!disposing)
     {
         return;
     }
     _hmac?.Dispose();
     if (_buffer != null)
     {
         Array.Clear(_buffer, 0, _buffer.Length);
     }
     if (_salt != null)
     {
         Array.Clear(_salt, 0, _salt.Length);
     }
 }
Esempio n. 22
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                _baseStream.Dispose();

                _cryptoEncryptor.Dispose();
                _cryptoDecryptor.Dispose();

                _encryptionKey.Dispose();

                _authHMACEncrypt.Dispose();
                _authHMACDecrypt.Dispose();
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Esempio n. 23
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                if (_PRF != null)
                {
                    _PRF.Dispose();
                }
            }

            _disposed = true;

            base.Dispose(disposing);
        }
Esempio n. 24
0
File: Hkdf.cs Progetto: jdluzen/Hkdf
        /// <summary>
        /// Releases all resources used by the <see cref="Hkdf"/>.
        /// </summary>
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            if (_hmac != null)
            {
                _hmac.Dispose();
            }

            if (_tInfoN != null)
            {
                Array.Clear(_tInfoN, 0, _tInfoN.Length);
                _tInfoN = null;
            }

            _disposed = true;
        }
Esempio n. 25
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                //send close channel signal
                lock (_writeLock)
                {
                    try
                    {
                        FlushBuffer(HEADER_FLAG_CLOSE_CHANNEL);
                    }
                    catch
                    { }
                }

                //dispose
                _baseStream?.Dispose();

                _renegotiationTimer?.Dispose();

                _encryptor?.Dispose();
                _decryptor?.Dispose();

                _encryptionAlgo?.Dispose();
                _decryptionAlgo?.Dispose();

                _authHMACEncrypt?.Dispose();
                _authHMACDecrypt?.Dispose();
            }

            _disposed = true;

            base.Dispose(disposing);
        }
Esempio n. 26
0
            protected virtual void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (_inner != null)
                    {
                        _inner.Dispose();
                        _inner = null;
                    }

                    if (_hmac != null)
                    {
                        _hmac.Dispose();
                        _hmac = null;
                    }

                    if (_aes != null)
                    {
                        _aes.Dispose();
                        _aes = null;
                    }
                }
            }
Esempio n. 27
0
 public override void Dispose()
 {
     macEngine?.Dispose();
 }
Esempio n. 28
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _hmac?.Dispose();
 }
Esempio n. 29
0
 public void Dispose()
 {
     HMAC.Dispose();
 }
Esempio n. 30
0
        protected override void Dispose(bool disposing)
        {
            _PRF.Dispose();

            base.Dispose(disposing);
        }