public static extern SECURITY_STATUS NCryptCreatePersistedKey( SafeProviderHandle hProvider, out SafeKeyHandle phKey, string pszAlgId, string pszKeyName = null, LegacyKeySpec dwLegacyKeySpec = LegacyKeySpec.None, NCryptCreatePersistedKeyFlags dwFlags = NCryptCreatePersistedKeyFlags.None);
/// <summary> /// Opens a key that exists in the specified CNG key storage provider. /// </summary> /// <param name="provider">The handle of the key storage provider to open the key from.</param> /// <param name="keyName">A pointer to a null-terminated Unicode string that contains the name of the key to retrieve.</param> /// <param name="legacyKeySpec">A legacy identifier that specifies the type of key.</param> /// <param name="flags">Flags that modify function behavior.</param> /// <returns> /// A pointer to a NCRYPT_KEY_HANDLE variable that receives the key handle. When you have finished using this handle, release it by calling its <see cref="SafeHandle.Dispose()"/> method. /// </returns> public static SafeKeyHandle NCryptOpenKey( SafeProviderHandle provider, string keyName, LegacyKeySpec legacyKeySpec, NCryptOpenKeyFlags flags = NCryptOpenKeyFlags.None) { SafeKeyHandle key; NCryptOpenKey( provider, out key, keyName, legacyKeySpec, flags).ThrowOnError(); return(key); }
/// <summary> /// Creates a new key and stores it in the specified key storage provider. After you create a key by using this function, you can use the NCryptSetProperty function to set its properties; however, the key cannot be used until the NCryptFinalizeKey function is called. /// </summary> /// <param name="provider"> /// The handle of the key storage provider to create the key in. This handle is obtained by using the <see cref="NCryptOpenStorageProvider(string, NCryptOpenStorageProviderFlags)"/> function. /// </param> /// <param name="algorithmId"> /// A null-terminated Unicode string that contains the identifier of the cryptographic algorithm to create the key. This can be one of the standard CNG Algorithm Identifiers defined in <see cref="BCrypt.AlgorithmIdentifiers"/> or the identifier for another registered algorithm. /// </param> /// <param name="keyName"> /// A pointer to a null-terminated Unicode string that contains the name of the key. If this parameter is NULL, this function will create an ephemeral key that is not persisted. /// </param> /// <param name="legacyKeySpec"> /// A legacy identifier that specifies the type of key. /// </param> /// <param name="flags">A set of flags that modify the behavior of this function.</param> /// <returns> /// The address of an <see cref="SafeKeyHandle"/> variable that receives the handle of the key. When you have finished using this handle, release it by disposing it. /// </returns> public static SafeKeyHandle NCryptCreatePersistedKey( SafeProviderHandle provider, string algorithmId, string keyName = null, LegacyKeySpec legacyKeySpec = LegacyKeySpec.None, NCryptCreatePersistedKeyFlags flags = NCryptCreatePersistedKeyFlags.None) { SafeKeyHandle result; NCryptCreatePersistedKey( provider, out result, algorithmId, keyName, legacyKeySpec, flags).ThrowOnError(); return(result); }
public static extern SECURITY_STATUS NCryptOpenKey( SafeProviderHandle hProvider, out SafeKeyHandle phKey, string pszKeyName, LegacyKeySpec dwLegacyKeySpec, NCryptOpenKeyFlags dwFlags = NCryptOpenKeyFlags.None);