示例#1
0
 private void Reset()
 {
     this.platformKey?.Dispose();
     this.platformKey = null;
     this.platformAlgorithm?.Dispose();
     this.platformAlgorithm = null;
 }
示例#2
0
 public static extern NTSTATUS BCryptOpenAlgorithmProvider(
     out SafeAlgorithmHandle phAlgorithm,
     string pszAlgId,
     string pszImplementation,
     BCryptOpenAlgorithmProviderFlags dwFlags);
示例#3
0
 public static extern NTSTATUS BCryptGenRandom(
     SafeAlgorithmHandle hAlgorithm,
     byte[] pbBuffer,
     int cbBuffer,
     BCryptGenRandomFlags flags = BCryptGenRandomFlags.None);
示例#4
0
 public static extern NTSTATUS BCryptGenerateSymmetricKey(
     SafeAlgorithmHandle hAlgorithm,
     out SafeKeyHandle phKey,
     byte[] pbKeyObject,
     int cbKeyObject,
     byte[] pbSecret,
     int cbSecret,
     BCryptGenerateSymmetricKeyFlags flags = BCryptGenerateSymmetricKeyFlags.None);
示例#5
0
 public static extern NTSTATUS BCryptImportKeyPair(
     SafeAlgorithmHandle hAlgorithm,
     SafeKeyHandle hImportKey,
     [MarshalAs(UnmanagedType.LPWStr)] string pszBlobType,
     out SafeKeyHandle phKey,
     byte[] pbInput,
     int cbInput,
     BCryptImportKeyPairFlags dwFlags);
示例#6
0
 public static extern NTSTATUS BCryptCreateHash(
     SafeAlgorithmHandle hAlgorithm,
     out SafeHashHandle phHash,
     byte[] pbHashObject,
     int cbHashObject,
     byte[] pbSecret,
     int cbSecret,
     BCryptCreateHashFlags dwFlags);
示例#7
0
 public static extern NTSTATUS BCryptGenerateKeyPair(
     SafeAlgorithmHandle hAlgorithm,
     out SafeKeyHandle phKey,
     int dwLength,
     BCryptGenerateKeyPairFlags dwFlags = BCryptGenerateKeyPairFlags.None);
示例#8
0
 /// <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;
 }
示例#9
0
 /// <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;
 }
示例#10
0
 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;
 }
示例#11
0
 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);
示例#12
0
 private static extern NTSTATUS BCryptImportKey(SafeAlgorithmHandle hAlgorithm, IntPtr hImportKey, string pszBlobType, out SafeKeyHandle hKey, IntPtr pbKeyObject, int cbKeyObject, byte[] pbInput, int cbInput, int dwFlags);