Esempio n. 1
0
        protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
        {
            // we're sealed and the base should have checked this already
            Contract.Assert(data != null);
            Contract.Assert(!String.IsNullOrEmpty(hashAlgorithm.Name));

#if MONO
            var hash = HashAlgorithm.Create(hashAlgorithm.Name);
            return(hash.ComputeHash(data));
#else
            using (SafeHashHandle hashHandle = Utils.CreateHash(Utils.StaticProvHandle, GetAlgorithmId(hashAlgorithm))) {
                // Read the data 4KB at a time, providing similar read characteristics to a standard HashAlgorithm
                byte[] buffer    = new byte[4096];
                int    bytesRead = 0;
                do
                {
                    bytesRead = data.Read(buffer, 0, buffer.Length);
                    if (bytesRead > 0)
                    {
                        Utils.HashData(hashHandle, buffer, 0, bytesRead);
                    }
                } while (bytesRead > 0);

                return(Utils.EndHash(hashHandle));
            }
#endif
        }
 public override void Initialize()
 {
     if (this._safeHashHandle != null && !this._safeHashHandle.IsClosed)
     {
         this._safeHashHandle.Dispose();
     }
     this._safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, 32772);
 }
 protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
 {
     using (SafeHashHandle hash = Utils.CreateHash(Utils.StaticProvHandle, RSACryptoServiceProvider.GetAlgorithmId(hashAlgorithm)))
     {
         Utils.HashData(hash, data, offset, count);
         return(Utils.EndHash(hash));
     }
 }
 public MD5CryptoServiceProvider()
 {
     if (CryptoConfig.AllowOnlyFipsAlgorithms)
     {
         throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
     }
     this._safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, 0x8003);
 }
Esempio n. 5
0
        public override void Initialize()
        {
            if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
            {
                _safeHashHandle.Dispose();
            }

            _safeHashHandle = Utils.CreateHash(CALG_MD4);
        }
        [System.Security.SecuritySafeCritical]  // auto-generated
        public override void Initialize()
        {
            if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
            {
                _safeHashHandle.Dispose();
            }

            // _CreateHash will check for failures and throw the appropriate exception
            _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_MD5);
        }
Esempio n. 7
0
 public MD4CryptoServiceProvider()
 {
     if (CryptoConfig.AllowOnlyFipsAlgorithms)
     {
         throw new InvalidOperationException("Cryptography_NonCompliantFIPSAlgorithm");
     }
     Contract.EndContractBlock();
     // cheat with Reflection
     _safeHashHandle = Utils.CreateHash(CALG_MD4);
 }
        [System.Security.SecuritySafeCritical]  // auto-generated
        public MD5CryptoServiceProvider()
        {
            if (CryptoConfig.AllowOnlyFipsAlgorithms)
            {
                throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
            }
            Contract.EndContractBlock();

            // _CreateHash will check for failures and throw the appropriate exception
            _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_MD5);
        }
Esempio n. 9
0
        protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
        {
            // we're sealed and the base should have checked this already
            Contract.Assert(data != null);
            Contract.Assert(offset >= 0 && offset <= data.Length);
            Contract.Assert(count >= 0 && count <= data.Length);
            Contract.Assert(!String.IsNullOrEmpty(hashAlgorithm.Name));

            using (SafeHashHandle hashHandle = Utils.CreateHash(Utils.StaticProvHandle, GetAlgorithmId(hashAlgorithm))) {
                Utils.HashData(hashHandle, data, offset, count);
                return(Utils.EndHash(hashHandle));
            }
        }
        [System.Security.SecuritySafeCritical]  // auto-generated
        public MD5CryptoServiceProvider()
        {
            // .NET Framework 2.0 - 4.7.2 rejected MD5 when in FIPS mode because it was not
            // an approved algorithm.  Since this caused problems for legitimate applications
            // this is no longer done, an application or library needs to determine on its own
            // if MD5 is prohibited in context.
            if (CryptoConfig.AllowOnlyFipsAlgorithms && AppContextSwitches.UseLegacyFipsThrow)
            {
                throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
            }
            Contract.EndContractBlock();

            // _CreateHash will check for failures and throw the appropriate exception
            _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_MD5);
        }
 protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
 {
     using (SafeHashHandle hash = Utils.CreateHash(Utils.StaticProvHandle, RSACryptoServiceProvider.GetAlgorithmId(hashAlgorithm)))
     {
         byte[] numArray = new byte[4096];
         int    cbSize;
         do
         {
             cbSize = data.Read(numArray, 0, numArray.Length);
             if (cbSize > 0)
             {
                 Utils.HashData(hash, numArray, 0, cbSize);
             }
         }while (cbSize > 0);
         return(Utils.EndHash(hash));
     }
 }
 protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
 {
     byte[] result;
     using (SafeHashHandle safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, RSACryptoServiceProvider.GetAlgorithmId(hashAlgorithm)))
     {
         byte[] array = new byte[4096];
         int    num;
         do
         {
             num = data.Read(array, 0, array.Length);
             if (num > 0)
             {
                 Utils.HashData(safeHashHandle, array, 0, num);
             }
         }while (num > 0);
         result = Utils.EndHash(safeHashHandle);
     }
     return(result);
 }
 public SHA1CryptoServiceProvider()
 {
     this._safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, 32772);
 }
Esempio n. 14
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 public SHA1Managed()
 {
     // _CreateHash will check for failures and throw the appropriate exception
     _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_SHA1);
 }