Exemple #1
0
        public static SafeHashHandle BCryptCreateHash(this SafeAlgorithmHandle hAlgorithm, byte[] pbSecret, int dwFlags)
        {
            SafeHashHandle hHash    = null;
            NTSTATUS       ntStatus = Interop.BCryptCreateHash(hAlgorithm, out hHash, IntPtr.Zero, 0, pbSecret, pbSecret == null ? 0 : pbSecret.Length, dwFlags);

            if (ntStatus != NTSTATUS.STATUS_SUCCESS)
            {
                throw CreateCryptographicException(ntStatus);
            }
            return(hHash);
        }
Exemple #2
0
        public static SafeHashHandle BCryptTryCreateReusableHash(this SafeAlgorithmHandle hAlgorithm, byte[] pbSecret)
        {
            const int BCRYPT_HASH_REUSABLE_FLAG = 0x00000020;

            SafeHashHandle hHash    = null;
            NTSTATUS       ntStatus = Interop.BCryptCreateHash(hAlgorithm, out hHash, IntPtr.Zero, 0, pbSecret, pbSecret == null ? 0 : pbSecret.Length, BCRYPT_HASH_REUSABLE_FLAG);

            if (ntStatus == NTSTATUS.STATUS_INVALID_PARAMETER)
            {
                return(null);  // Pre-Win8 OS's do not support BCRYPT_HASH_REUSABLE_FLAG.
            }
            if (ntStatus != NTSTATUS.STATUS_SUCCESS)
            {
                throw CreateCryptographicException(ntStatus);
            }
            return(hHash);
        }