private void Reset() { this.platformKey?.Dispose(); this.platformKey = null; this.platformAlgorithm?.Dispose(); this.platformAlgorithm = null; }
public static extern NTSTATUS BCryptOpenAlgorithmProvider( out SafeAlgorithmHandle phAlgorithm, string pszAlgId, string pszImplementation, BCryptOpenAlgorithmProviderFlags dwFlags);
public static extern NTSTATUS BCryptGenRandom( SafeAlgorithmHandle hAlgorithm, byte[] pbBuffer, int cbBuffer, BCryptGenRandomFlags flags = BCryptGenRandomFlags.None);
public static extern NTSTATUS BCryptGenerateSymmetricKey( SafeAlgorithmHandle hAlgorithm, out SafeKeyHandle phKey, byte[] pbKeyObject, int cbKeyObject, byte[] pbSecret, int cbSecret, BCryptGenerateSymmetricKeyFlags flags = BCryptGenerateSymmetricKeyFlags.None);
public static extern NTSTATUS BCryptImportKeyPair( SafeAlgorithmHandle hAlgorithm, SafeKeyHandle hImportKey, [MarshalAs(UnmanagedType.LPWStr)] string pszBlobType, out SafeKeyHandle phKey, byte[] pbInput, int cbInput, BCryptImportKeyPairFlags dwFlags);
public static extern NTSTATUS BCryptCreateHash( SafeAlgorithmHandle hAlgorithm, out SafeHashHandle phHash, byte[] pbHashObject, int cbHashObject, byte[] pbSecret, int cbSecret, BCryptCreateHashFlags dwFlags);
public static extern NTSTATUS BCryptGenerateKeyPair( SafeAlgorithmHandle hAlgorithm, out SafeKeyHandle phKey, int dwLength, BCryptGenerateKeyPairFlags dwFlags = BCryptGenerateKeyPairFlags.None);
/// <summary> /// Gets the minimum length of a key (in bits). /// </summary> /// <param name="algorithm">The algorithm.</param> /// <returns>The length of the smallest key, in bits.</returns> private static int GetMinimumKeySize(SafeAlgorithmHandle algorithm) { var keyLengths = BCryptGetProperty<BCRYPT_KEY_LENGTHS_STRUCT>(algorithm, PropertyNames.BCRYPT_KEY_LENGTHS); return keyLengths.MinLength; }
/// <summary> /// Creates an empty public/private key pair. /// </summary> /// <param name="algorithm">The handle to the algorithm previously opened by <see cref="BCryptOpenAlgorithmProvider"/></param> /// <param name="keyLength">The length of the key, in bits.</param> /// <returns>A handle to the generated key pair.</returns> /// <remarks> /// After you create a key by using this function, you can use the BCryptSetProperty /// function to set its properties; however, the key cannot be used until the /// BCryptFinalizeKeyPair function is called. /// </remarks> public static SafeKeyHandle BCryptGenerateKeyPair( SafeAlgorithmHandle algorithm, int keyLength) { SafeKeyHandle result; var error = BCryptGenerateKeyPair(algorithm, out result, keyLength, 0); error.ThrowOnError(); return result; }
public static SafeKeyHandle BCryptImportKeyPair( SafeAlgorithmHandle algorithm, string blobType, byte[] input, BCryptImportKeyPairFlags flags) { SafeKeyHandle result; var error = BCryptImportKeyPair( algorithm, SafeKeyHandle.NullHandle, blobType, out result, input, input.Length, flags); error.ThrowOnError(); return result; }
public static extern NTStatus BCryptImportKey( SafeAlgorithmHandle hAlgorithm, SafeKeyHandle hImportKey, [MarshalAs(UnmanagedType.LPWStr)] string pszBlobType, out SafeKeyHandle phKey, byte[] pbKeyObject, int cbKeyObject, byte[] pbInput, int cbInput, BCryptImportKeyFlags dwFlags = BCryptImportKeyFlags.None);
private static extern NTSTATUS BCryptImportKey(SafeAlgorithmHandle hAlgorithm, IntPtr hImportKey, string pszBlobType, out SafeKeyHandle hKey, IntPtr pbKeyObject, int cbKeyObject, byte[] pbInput, int cbInput, int dwFlags);