Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
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();
 }