namespace com.hitrust.Security.Cryptography { using com.hitrust.Security; using System; using System.Runtime.InteropServices; using System.Security.Cryptography; public sealed class MD4CryptoServiceProvider : MD4 { private bool m_Disposed; private int m_Hash; private int m_Provider = 0; public MD4CryptoServiceProvider() { if ((SspiProvider.CryptAcquireContext(ref this.m_Provider, IntPtr.Zero, null, 1, 0) == 0) && (Marshal.GetLastWin32Error() == -2146893802)) { SspiProvider.CryptAcquireContext(ref this.m_Provider, IntPtr.Zero, null, 1, 8); } this.Initialize(); this.m_Disposed = false; } protected override void Dispose(bool disposing) { if (!this.m_Disposed) { if (this.m_Hash != 0) { SspiProvider.CryptDestroyHash(this.m_Hash); this.m_Hash = 0; } if (this.m_Provider != 0) { SspiProvider.CryptReleaseContext(this.m_Provider, 0); this.m_Provider = 0; } try { GC.SuppressFinalize(this); } catch { } this.m_Disposed = true; } } ~MD4CryptoServiceProvider() { base.Clear(); } protected override void HashCore(byte[] array, int ibStart, int cbSize) { if (this.m_Disposed) { throw new ObjectDisposedException(base.GetType().FullName); } byte[] copy = new byte[cbSize]; Array.Copy(array, ibStart, copy, 0, cbSize); if (SspiProvider.CryptHashData(this.m_Hash, copy, copy.Length, 0) == 0) { throw new CryptographicException("The data could not be hashed."); } } protected override byte[] HashFinal() { if (this.m_Disposed) { throw new ObjectDisposedException(base.GetType().FullName); } byte[] buffer = new byte[0x10]; int length = buffer.Length; if (SspiProvider.CryptGetHashParam(this.m_Hash, 2, buffer, ref length, 0) == 0) { throw new CryptographicException("The hash value could not be read."); } return buffer; } public override void Initialize() { if (this.m_Disposed) { throw new ObjectDisposedException(base.GetType().FullName); } if (this.m_Hash != 0) { SspiProvider.CryptDestroyHash(this.m_Hash); } SspiProvider.CryptCreateHash(this.m_Provider, 0x8002, 0, 0, out this.m_Hash); } } }