Beispiel #1
0
            public string HMACSign(byte[] data, string key, SigningAlgorithm algorithmName)
            {
                if (String.IsNullOrEmpty(key))
                {
                    throw new ArgumentNullException("key", "Please specify a Secret Signing Key.");
                }

                if (data == null || data.Length == 0)
                {
                    throw new ArgumentNullException("data", "Please specify data to sign.");
                }

                KeyedHashAlgorithm algorithm = CreateKeyedHashAlgorithm(algorithmName);

                if (null == algorithm)
                {
                    throw new InvalidOperationException("Please specify a KeyedHashAlgorithm to use.");
                }

                try
                {
                    algorithm.Key = Encoding.UTF8.GetBytes(key);
                    byte[] bytes = algorithm.ComputeHash(data);
                    return(Convert.ToBase64String(bytes));
                }
                finally
                {
                    algorithm.Dispose();
                }
            }
Beispiel #2
0
            public byte[] HMACSignBinary(byte[] data, byte[] key, SigningAlgorithm algorithmName)
            {
                if (key == null || key.Length == 0)
                {
                    throw new ArgumentNullException("key", "Please specify a Secret Signing Key.");
                }

                if (data == null || data.Length == 0)
                {
                    throw new ArgumentNullException("data", "Please specify data to sign.");
                }

                KeyedHashAlgorithm algorithm = CreateKeyedHashAlgorithm(algorithmName);

                if (null == algorithm)
                {
                    throw new InvalidOperationException("Please specify a KeyedHashAlgorithm to use.");
                }

                try
                {
                    algorithm.Key = key;
                    byte[] bytes = algorithm.ComputeHash(data);
                    return(bytes);
                }
                finally
                {
                    algorithm.Dispose();
                }
            }
Beispiel #3
0
        /// <summary>
        /// Closes the stream, clearing memory and disposing of the HMAC algorithm.
        /// </summary>
        //public override void Close()
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            Security.Clear(_saltBuffer);
            Security.Clear(_digest);
            Security.Clear(_digestT1);
            //_hmacAlgorithm.Clear();
            _hmacAlgorithm.Dispose();
        }
Beispiel #4
0
        /// <summary>
        /// Performs the actual job of disposing the object.
        /// </summary>
        /// <param name="disposing">
        /// Passes the information whether this method is called by <see cref="Dispose()"/> (explicitly or
        /// implicitly at the end of a <c>using</c> statement), or by the <see cref="M:~Hasher"/>.
        /// </param>
        /// <remarks>
        /// If the method is called with <paramref name="disposing"/><c>==true</c>, i.e. from <see cref="Dispose()"/>,
        /// it will try to release all managed resources (usually aggregated objects which implement <see cref="IDisposable"/> as well)
        /// and then it will release all unmanaged resources if any. If the parameter is <c>false</c> then
        /// the method will only try to release the unmanaged resources.
        /// </remarks>
        protected virtual void Dispose(bool disposing)
        {
            // if it is disposed or in a process of disposing - return.
            if (Interlocked.Exchange(ref _disposed, 1) != 0)
            {
                return;
            }

            if (disposing)
            {
                _hashAlgorithm.Dispose();
            }
        }
        /// <summary>
        /// Disposes of internal components.
        /// </summary>
        /// <param name="disposing">true, if called from Dispose(), false, if invoked inside a finalizer.</param>
        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                _disposed = true;

                if (disposing)
                {
                    if (_keyedHash != null)
                    {
                        _keyedHash.Dispose();
                        _keyedHash = null;
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Disposes of internal components.
        /// </summary>
        /// <param name="disposing">true, if called from Dispose(), false, if invoked inside a finalizer.</param>
        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                _disposed = true;
                CryptoProviderCache?.TryRemove(this);

                if (disposing)
                {
                    if (_keyedHash != null)
                    {
                        _keyedHash.Dispose();
                        _keyedHash = null;
                    }
                }
            }
        }
Beispiel #7
0
 public override void Dispose()
 {
     algorithm.Dispose();
 }
Beispiel #8
0
 public void Dispose()
 {
     _ct.Dispose();
     _mac.Dispose();
 }
Beispiel #9
0
 public void Dispose()
 {
     _realAlgorithm?.Dispose();
 }
 public void Dispose()
 {
     _keyedHash.Dispose();
 }
Beispiel #11
0
 public void Dispose()
 {
     _hmac.Dispose();
 }