예제 #1
0
		protected override void Dispose(bool disposing)
		{
			base.Dispose(disposing);

			if (hmac != null)
				hmac.Dispose();
		}
예제 #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);
            }
예제 #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;
        }
예제 #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;
     }
 }
예제 #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;
     }
 }
예제 #8
0
 private void DisposeHmac()
 {
     if (_Hmac != null)
     {
         Array.Clear(_Hmac.Key, 0, _Hmac.Key.Length);
         _Hmac.Dispose();
         _Hmac = null;
     }
 }
예제 #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);
        }
예제 #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);
                }
        }
예제 #11
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            _secretHmac.Dispose();
            _tagHmac.Dispose();
            _prf.Dispose();
            _disposed = true;
        }
예제 #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 _));
        }
예제 #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;
            }
        }
예제 #15
0
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

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

            _disposed = true;
        }
예제 #16
0
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

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

            _disposed = true;
        }
예제 #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;
            }
        }
예제 #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;
            }
        }
예제 #19
0
        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;
        }
예제 #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);
     }
 }
예제 #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);
            }
        }
예제 #23
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

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

            _disposed = true;

            base.Dispose(disposing);
        }
예제 #24
0
파일: Hkdf.cs 프로젝트: 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;
        }
예제 #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);
        }
예제 #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;
                    }
                }
            }
예제 #27
0
 public override void Dispose()
 {
     macEngine?.Dispose();
 }
예제 #28
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _hmac?.Dispose();
 }
예제 #29
0
 public void Dispose()
 {
     HMAC.Dispose();
 }
예제 #30
0
        protected override void Dispose(bool disposing)
        {
            _PRF.Dispose();

            base.Dispose(disposing);
        }