Inheritance: SafeBCryptHandle
コード例 #1
0
        public static unsafe void BCryptHashData(this SafeHashHandle hHash, byte *pbInput, int cbInput)
        {
            NTSTATUS ntStatus = Interop.BCryptHashData(hHash, pbInput, cbInput, 0);

            if (ntStatus != NTSTATUS.STATUS_SUCCESS)
            {
                throw CreateCryptographicException(ntStatus);
            }
            return;
        }
コード例 #2
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);
        }
コード例 #3
0
        public static byte[] BCryptFinishHash(this SafeHashHandle hHash, int cbHashSize)
        {
            byte[]   hash     = new byte[cbHashSize];
            NTSTATUS ntStatus = Interop.BCryptFinishHash(hHash, hash, cbHashSize, 0);

            if (ntStatus != NTSTATUS.STATUS_SUCCESS)
            {
                throw CreateCryptographicException(ntStatus);
            }
            return(hash);
        }
コード例 #4
0
 public static int GetHashSizeInBytes(this SafeHashHandle hHash)
 {
     unsafe
     {
         int      cbSizeOfHashSize;
         int      hashSize;
         NTSTATUS ntStatus = Interop.BCryptGetProperty(hHash, BCryptGetPropertyStrings.BCRYPT_HASH_LENGTH, (byte *)&hashSize, 4, out cbSizeOfHashSize, 0);
         if (ntStatus != NTSTATUS.STATUS_SUCCESS)
         {
             throw CreateCryptographicException(ntStatus);
         }
         return(hashSize);
     }
 }
コード例 #5
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);
        }
コード例 #6
0
 public static extern NTSTATUS BCryptFinishHash(SafeHashHandle hHash, [Out] byte[] pbOutput, int cbOutput, int dwFlags);
コード例 #7
0
 public static extern unsafe NTSTATUS BCryptHashData(SafeHashHandle hHash, byte *pbInput, int cbInput, int dwFlags);
コード例 #8
0
 public static extern NTSTATUS BCryptCreateHash(SafeAlgorithmHandle hAlgorithm, out SafeHashHandle phHash, IntPtr pbHashObject, int cbHashObject, [In, Out] byte[] pbSecret, int cbSecret, int dwFlags);