コード例 #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
        }
コード例 #2
0
 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
        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));
            }
        }
コード例 #4
0
 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));
     }
 }
コード例 #5
0
 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);
 }
コード例 #6
0
 internal static byte[] EndHash(SafeHashHandle hHash)
 {
     byte[] o = (byte[])null;
     Utils.EndHash(hHash, JitHelpers.GetObjectHandleOnStack <byte[]>(ref o));
     return(o);
 }
コード例 #7
0
 [System.Security.SecuritySafeCritical] // overrides protected transparent member
 protected override byte[] HashFinal()
 {
     return(Utils.EndHash(_safeHashHandle));
 }
コード例 #8
0
 internal static byte[] EndHash(SafeHashHandle hHash)
 {
     byte[] result = null;
     Utils.EndHash(hHash, JitHelpers.GetObjectHandleOnStack <byte[]>(ref result));
     return(result);
 }