Example #1
0
 public static extern NtStatus BCryptCreateHash(
     IntPtr hAlgorithm,
     out IntPtr phHash,
     IntPtr pbHashObject,
     int cbHashObject,
     ref byte pbSecret,
     int cbSecrect,
     BCryptCreateHashFlags dwFlags = BCryptCreateHashFlags.None
     );
        /// <summary>
        /// Create a hash or Message Authentication Code (MAC) object.
        /// </summary>
        /// <param name="algorithm">
        /// The handle of an algorithm provider created by using the <see cref="BCryptOpenAlgorithmProvider(string, string, BCryptOpenAlgorithmProviderFlags)"/> function. The algorithm that was specified when the provider was created must support the hash interface.
        /// </param>
        /// <param name="hashObject">
        /// A pointer to a buffer that receives the hash or MAC object. The required size of this buffer can be obtained by calling the <see cref="BCryptGetProperty(SafeHandle, string, BCryptGetPropertyFlags)"/> function to get the <see cref="PropertyNames.BCRYPT_OBJECT_LENGTH"/> property. This will provide the size of the hash or MAC object for the specified algorithm.
        /// This memory can only be freed after the handle pointed to by the return value is destroyed.
        /// If the value of this parameter is NULL, the memory for the hash object is allocated and freed by this function.
        /// Windows 7:  This memory management functionality is available beginning with Windows 7.
        /// </param>
        /// <param name="secret">
        /// A pointer to a buffer that contains the key to use for the hash or MAC. This key only applies to hash algorithms opened by the BCryptOpenAlgorithmProvider function by using the <see cref="BCryptOpenAlgorithmProviderFlags.BCRYPT_ALG_HANDLE_HMAC_FLAG"/> flag. Otherwise, set this parameter to NULL.
        /// </param>
        /// <param name="flags">Flags that modify the behavior of the function.</param>
        /// <returns>
        /// A pointer to a <see cref="SafeHashHandle"/> value that receives a handle that represents the hash or MAC object. This handle is used in subsequent hashing or MAC functions, such as the <see cref="BCryptHashData(SafeHashHandle, byte*, int, BCryptHashDataFlags)"/> function. When you have finished using this handle, release it by passing it to the <see cref="BCryptDestroyHash"/> function.
        /// </returns>
        public static SafeHashHandle BCryptCreateHash(
            SafeAlgorithmHandle algorithm,
            byte[] hashObject           = null,
            byte[] secret               = null,
            BCryptCreateHashFlags flags = BCryptCreateHashFlags.None)
        {
            SafeHashHandle result;

            BCryptCreateHash(
                algorithm,
                out result,
                hashObject,
                hashObject?.Length ?? 0,
                secret,
                secret?.Length ?? 0,
                flags).ThrowOnError();
            return(result);
        }
Example #3
0
 internal static extern int BCryptCreateHash(SafeBCryptAlgorithmHandle algorithmHandle, out SafeBCryptHashHandle hashHandle, IntPtr hashObject, int hashObjectByteLength, [In, Out] byte[] secretBuffer, int secretByteLength, BCryptCreateHashFlags flags);
 internal static extern NTSTATUS BCryptCreateHash(SafeBCryptAlgorithmHandle hAlgorithm, out SafeBCryptHashHandle phHash, IntPtr pbHashObject, int cbHashObject, [In, Out] byte[] pbSecret, int cbSecret, BCryptCreateHashFlags dwFlags);
 internal static extern NTSTATUS BCryptCreateHash(SafeBCryptAlgorithmHandle hAlgorithm, out SafeBCryptHashHandle phHash, IntPtr pbHashObject, int cbHashObject, [In, Out] byte[] pbSecret, int cbSecret, BCryptCreateHashFlags dwFlags);
Example #6
0
 public static extern NTSTATUS BCryptCreateHash(
     SafeAlgorithmHandle hAlgorithm,
     out SafeHashHandle phHash,
     byte[] pbHashObject,
     int cbHashObject,
     byte[] pbSecret,
     int cbSecret,
     BCryptCreateHashFlags dwFlags);
 private static partial NTSTATUS BCryptCreateHash(SafeBCryptAlgorithmHandle hAlgorithm, out SafeBCryptHashHandle phHash, IntPtr pbHashObject, int cbHashObject, ref byte pbSecret, int cbSecret, BCryptCreateHashFlags dwFlags);
 internal static NTSTATUS BCryptCreateHash(SafeBCryptAlgorithmHandle hAlgorithm, out SafeBCryptHashHandle phHash, IntPtr pbHashObject, int cbHashObject, ReadOnlySpan <byte> secret, int cbSecret, BCryptCreateHashFlags dwFlags)
 {
     return(BCryptCreateHash(hAlgorithm, out phHash, pbHashObject, cbHashObject, ref MemoryMarshal.GetReference(secret), cbSecret, dwFlags));
 }
 internal static partial NTSTATUS BCryptCreateHash(SafeBCryptAlgorithmHandle hAlgorithm, out SafeBCryptHashHandle phHash, IntPtr pbHashObject, int cbHashObject, ReadOnlySpan <byte> secret, int cbSecret, BCryptCreateHashFlags dwFlags);