public static extern SECURITY_STATUS NCryptCreatePersistedKey( SafeProviderHandle hProvider, out SafeKeyHandle phKey, string pszAlgId, string pszKeyName = null, LegacyKeySpec dwLegacyKeySpec = LegacyKeySpec.None, NCryptCreatePersistedKeyFlags dwFlags = NCryptCreatePersistedKeyFlags.None);
public static extern unsafe SECURITY_STATUS NCryptImportKey( SafeProviderHandle hProvider, SafeKeyHandle hImportKey, string pszBlobType, NCryptBufferDesc *pParameterList, out SafeKeyHandle phKey, byte *pbData, int cbData, NCryptExportKeyFlags dwFlags = NCryptExportKeyFlags.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); }
/// <summary> /// Imports a Cryptography API: Next Generation (CNG) key from a memory BLOB. /// </summary> /// <param name="provider">The handle of the key storage provider.</param> /// <param name="importKey"> /// The handle of the cryptographic key with which the key data within the imported key BLOB was encrypted. This must be a handle to the same key that was passed in the hExportKey parameter of the NCryptExportKey function. If this parameter is NULL, the key BLOB is assumed to not be encrypted. /// </param> /// <param name="blobType"> /// A null-terminated Unicode string that contains an identifier that specifies the format of the key BLOB. These formats are specific to a particular key storage provider. Commonly a value from <see cref="AsymmetricKeyBlobTypes"/> or <see cref="SymmetricKeyBlobTypes"/>. /// </param> /// <param name="parameterList"> /// The address of an <see cref="NCryptBufferDesc"/> structure that points to an array of buffers that contain parameter information for the key. /// </param> /// <param name="keyData">The address of a buffer that contains the key BLOB to be imported.</param> /// <param name="flags">Flags that modify function behavior.</param> /// <returns>Returns a status code that indicates the success or failure of the function.</returns> /// <remarks> /// If a key name is not supplied, the Microsoft Software KSP treats the key as ephemeral and does not store it persistently. For the NCRYPT_OPAQUETRANSPORT_BLOB type, the key name is stored within the BLOB when it is exported. For other BLOB formats, the name can be supplied in an NCRYPTBUFFER_PKCS_KEY_NAME buffer parameter within the pParameterList parameter. /// On Windows Server 2008 and Windows Vista, only keys imported as PKCS #7 envelope BLOBs (NCRYPT_PKCS7_ENVELOPE_BLOB) or PKCS #8 private key BLOBs (NCRYPT_PKCS8_PRIVATE_KEY_BLOB) can be persisted by using the above method. To persist keys imported through other BLOB types on these platforms, use the method documented in Key Import and Export. /// </remarks> public static unsafe SafeKeyHandle NCryptImportKey( SafeProviderHandle provider, SafeKeyHandle importKey, string blobType, NCryptBufferDesc *parameterList, byte[] keyData, NCryptExportKeyFlags flags = NCryptExportKeyFlags.None) { fixed(byte *pKeyData = keyData) { SafeKeyHandle importedKey; NCryptImportKey( provider, importKey ?? SafeKeyHandle.Null, blobType, parameterList, out importedKey, pKeyData, keyData.Length, flags).ThrowOnError(); return(importedKey); } }
/// <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">The description of the key to open.</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, NCryptKeyName keyName) { return(NCryptOpenKey(provider, keyName.Name, keyName.dwLegacyKeySpec, (NCryptOpenKeyFlags)keyName.dwFlags)); }
public static extern SECURITY_STATUS NCryptIsAlgSupported( SafeProviderHandle hProvider, string pszAlgId, NCryptIsAlgSupportedFlags dwFlags = NCryptIsAlgSupportedFlags.None);
public static extern SECURITY_STATUS NCryptOpenStorageProvider( out SafeProviderHandle phProvider, string pszProviderName, NCryptOpenStorageProviderFlags dwFlags = NCryptOpenStorageProviderFlags.None);
public static extern unsafe SECURITY_STATUS NCryptEnumKeys( SafeProviderHandle hProvider, string pszScope, out NCryptKeyName* ppKeyName, ref void* ppEnumState, NCryptEnumKeysFlags dwFlags = NCryptEnumKeysFlags.None);
public static extern SECURITY_STATUS NCryptOpenKey( SafeProviderHandle hProvider, out SafeKeyHandle phKey, string pszKeyName, LegacyKeySpec dwLegacyKeySpec, NCryptOpenKeyFlags dwFlags = NCryptOpenKeyFlags.None);
public static extern unsafe SECURITY_STATUS NCryptImportKey( SafeProviderHandle hProvider, SafeKeyHandle hImportKey, string pszBlobType, NCryptBufferDesc* pParameterList, out SafeKeyHandle phKey, byte* pbData, int cbData, NCryptExportKeyFlags dwFlags = NCryptExportKeyFlags.None);
public static extern unsafe SECURITY_STATUS NCryptEnumAlgorithms( SafeProviderHandle hProvider, AlgorithmOperations dwAlgOperations, out int pdwAlgCount, out NCryptAlgorithmName* ppAlgList, NCryptEnumAlgorithmsFlags dwFlags = NCryptEnumAlgorithmsFlags.None);
public static extern unsafe SECURITY_STATUS NCryptEnumKeys( SafeProviderHandle hProvider, string pszScope, out NCryptKeyName *ppKeyName, ref void *ppEnumState, NCryptEnumKeysFlags dwFlags = NCryptEnumKeysFlags.None);
public static extern unsafe SECURITY_STATUS NCryptEnumAlgorithms( SafeProviderHandle hProvider, AlgorithmOperations dwAlgOperations, out int pdwAlgCount, out NCryptAlgorithmName *ppAlgList, NCryptEnumAlgorithmsFlags dwFlags = NCryptEnumAlgorithmsFlags.None);
public SECURITY_STATUS NCryptOpenStorageProvider( out SafeProviderHandle phProvider, string pszProviderName, NCryptOpenStorageProviderFlags dwFlags = NCryptOpenStorageProviderFlags.None) => NCryptOpenStorageProvider(out phProvider, pszProviderName, dwFlags );