protected sealed override bool ReleaseHandle() { IntPtr localHandle = handle; handle = IntPtr.Zero; int status = MD5PInvokeHelper.BCryptDestroyHash(localHandle); return(status == MD5PInvokeHelper.StatusSuccess); }
protected sealed override bool ReleaseHandle() { IntPtr localHandle = handle; handle = IntPtr.Zero; int status = MD5PInvokeHelper.BCryptCloseAlgorithmProvider(localHandle, 0); return(status == MD5PInvokeHelper.StatusSuccess); }
internal static byte[] CalculateHash(byte[] inputBuffer) { byte[] hashResult; int status; SafeBCryptHashHandle hashHandle = null; status = MD5PInvokeHelper.BCryptCreateHash(MD5PInvokeHelper.MD5AlgorithmProvider, out hashHandle, IntPtr.Zero, 0, null, 0, 0); if (status != MD5PInvokeHelper.StatusSuccess) { DisposeMD5Handles(); throw new CryptographicException(status); } using (hashHandle) { int sizeOfHashSize; int hashSize; unsafe { status = MD5PInvokeHelper.BCryptGetProperty(hashHandle, MD5PInvokeHelper.BCryptHashLength, &hashSize, sizeof(int), out sizeOfHashSize, 0); if (status != MD5PInvokeHelper.StatusSuccess) { DisposeMD5Handles(); throw new CryptographicException(status); } } unsafe { fixed(byte *inputBytePointer = inputBuffer) { status = MD5PInvokeHelper.BCryptHashData(hashHandle, inputBytePointer, inputBuffer.Length, 0); if (status != MD5PInvokeHelper.StatusSuccess) { DisposeMD5Handles(); throw new CryptographicException(status); } } } hashResult = new byte[hashSize]; status = MD5PInvokeHelper.BCryptFinishHash(hashHandle, hashResult, hashResult.Length, 0); if (status != MD5PInvokeHelper.StatusSuccess) { DisposeMD5Handles(); throw new CryptographicException(status); } } // hashHandle has been disposed by the end of the "using" block. hashHandle = null; return(hashResult); }