Пример #1
0
        /// <summary>
        /// Finalizes the hash computation after the last data is processed by the cryptographic stream object.
        /// </summary>
        /// <returns>The computed hash code.</returns>
        protected override byte[] HashFinal()
        {
            byte[] hashBytes  = new byte[16];
            int    hashLength = hashBytes.Length;

            NativeMD5.ValidateReturnCode(NativeMethods.CryptGetHashParam(this.hashHandle, HashVal, hashBytes, ref hashLength, 0));
            return(hashBytes);
        }
Пример #2
0
        /// <summary>
        /// Initializes an implementation of the NativeMD5 class.
        /// </summary>
        public override void Initialize()
        {
            if (this.hashHandle != IntPtr.Zero)
            {
                NativeMethods.CryptDestroyHash(this.hashHandle);
                this.hashHandle = IntPtr.Zero;
            }

            NativeMD5.ValidateReturnCode(NativeMethods.CryptCreateHash(this.hashProv, CalgMD5, IntPtr.Zero, 0, out this.hashHandle));
        }
Пример #3
0
        /// <summary>
        /// Routes data written to the object into the hash algorithm for computing the hash.
        /// </summary>
        /// <param name="array">The input to compute the hash code for.</param>
        /// <param name="offset">The offset into the byte array from which to begin using data.</param>
        /// <param name="dataLen">The number of bytes in the byte array to use as data.</param>
        protected override void HashCore(byte[] array, int offset, int dataLen)
        {
            GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);

            try
            {
                IntPtr buffPtr = handle.AddrOfPinnedObject();
                if (offset != 0)
                {
                    buffPtr = IntPtr.Add(buffPtr, offset);
                }

                NativeMD5.ValidateReturnCode(NativeMethods.CryptHashData(this.hashHandle, buffPtr, dataLen, 0));
            }
            finally
            {
                handle.Free();
            }
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of NativeMD5.
 /// </summary>
 public NativeMD5()
     : base()
 {
     NativeMD5.ValidateReturnCode(NativeMethods.CryptAcquireContextW(out this.hashProv, null, null, ProvRsaFull, CryptVerifyContext));
     this.Initialize();
 }