예제 #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
        }
 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));
     }
 }
예제 #3
0
        internal static void HashData(SafeHashHandle hHash, byte[] data, int ibStart, int cbSize)
        {
            SafeHashHandle hHash1 = hHash;

            byte[] data1    = data;
            int    length   = data1.Length;
            int    ibStart1 = ibStart;
            int    cbSize1  = cbSize;

            Utils.HashData(hHash1, data1, length, ibStart1, cbSize1);
        }
예제 #4
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));
            }
        }
 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);
 }
예제 #7
0
 [System.Security.SecuritySafeCritical] // overrides protected transparent member
 protected override void HashCore(byte[] rgb, int ibStart, int cbSize)
 {
     Utils.HashData(_safeHashHandle, rgb, ibStart, cbSize);
 }
예제 #8
0
 internal static void HashData(SafeHashHandle hHash, byte[] data, int ibStart, int cbSize)
 {
     Utils.HashData(hHash, data, data.Length, ibStart, cbSize);
 }