コード例 #1
0
 public static extern SECURITY_STATUS NCryptCreatePersistedKey(
     SafeProviderHandle hProvider,
     out SafeKeyHandle phKey,
     string pszAlgId,
     string pszKeyName                     = null,
     LegacyKeySpec dwLegacyKeySpec         = LegacyKeySpec.None,
     NCryptCreatePersistedKeyFlags dwFlags = NCryptCreatePersistedKeyFlags.None);
コード例 #2
0
ファイル: NCrypt.cs プロジェクト: caioproiete/pinvoke
 public static extern SECURITY_STATUS NCryptCreatePersistedKey(
     SafeProviderHandle hProvider,
     out SafeKeyHandle phKey,
     string pszAlgId,
     string pszKeyName = null,
     LegacyKeySpec dwLegacyKeySpec = LegacyKeySpec.None,
     NCryptCreatePersistedKeyFlags dwFlags = NCryptCreatePersistedKeyFlags.None);
コード例 #3
0
 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);
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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);
            }
        }
コード例 #7
0
 /// <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));
 }
コード例 #8
0
 public static extern SECURITY_STATUS NCryptIsAlgSupported(
     SafeProviderHandle hProvider,
     string pszAlgId,
     NCryptIsAlgSupportedFlags dwFlags = NCryptIsAlgSupportedFlags.None);
コード例 #9
0
ファイル: NCrypt.cs プロジェクト: caioproiete/pinvoke
 public static extern SECURITY_STATUS NCryptOpenStorageProvider(
     out SafeProviderHandle phProvider,
     string pszProviderName,
     NCryptOpenStorageProviderFlags dwFlags = NCryptOpenStorageProviderFlags.None);
コード例 #10
0
ファイル: NCrypt.cs プロジェクト: hmemcpy/pinvoke
 public static extern unsafe SECURITY_STATUS NCryptEnumKeys(
     SafeProviderHandle hProvider,
     string pszScope,
     out NCryptKeyName* ppKeyName,
     ref void* ppEnumState,
     NCryptEnumKeysFlags dwFlags = NCryptEnumKeysFlags.None);
コード例 #11
0
ファイル: NCrypt.cs プロジェクト: hmemcpy/pinvoke
 public static extern SECURITY_STATUS NCryptIsAlgSupported(
     SafeProviderHandle hProvider,
     string pszAlgId,
     NCryptIsAlgSupportedFlags dwFlags = NCryptIsAlgSupportedFlags.None);
コード例 #12
0
 public static extern SECURITY_STATUS NCryptOpenKey(
     SafeProviderHandle hProvider,
     out SafeKeyHandle phKey,
     string pszKeyName,
     LegacyKeySpec dwLegacyKeySpec,
     NCryptOpenKeyFlags dwFlags = NCryptOpenKeyFlags.None);
コード例 #13
0
ファイル: NCrypt.cs プロジェクト: hmemcpy/pinvoke
 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);
コード例 #14
0
ファイル: NCrypt.cs プロジェクト: hmemcpy/pinvoke
 public static extern unsafe SECURITY_STATUS NCryptEnumAlgorithms(
     SafeProviderHandle hProvider,
     AlgorithmOperations dwAlgOperations,
     out int pdwAlgCount,
     out NCryptAlgorithmName* ppAlgList,
     NCryptEnumAlgorithmsFlags dwFlags = NCryptEnumAlgorithmsFlags.None);
コード例 #15
0
ファイル: NCrypt.cs プロジェクト: hmemcpy/pinvoke
 public static extern SECURITY_STATUS NCryptOpenKey(
     SafeProviderHandle hProvider,
     out SafeKeyHandle phKey,
     string pszKeyName,
     LegacyKeySpec dwLegacyKeySpec,
     NCryptOpenKeyFlags dwFlags = NCryptOpenKeyFlags.None);
コード例 #16
0
 public static extern unsafe SECURITY_STATUS NCryptEnumKeys(
     SafeProviderHandle hProvider,
     string pszScope,
     out NCryptKeyName *ppKeyName,
     ref void *ppEnumState,
     NCryptEnumKeysFlags dwFlags = NCryptEnumKeysFlags.None);
コード例 #17
0
 public static extern unsafe SECURITY_STATUS NCryptEnumAlgorithms(
     SafeProviderHandle hProvider,
     AlgorithmOperations dwAlgOperations,
     out int pdwAlgCount,
     out NCryptAlgorithmName *ppAlgList,
     NCryptEnumAlgorithmsFlags dwFlags = NCryptEnumAlgorithmsFlags.None);
コード例 #18
0
 public static extern SECURITY_STATUS NCryptOpenStorageProvider(
     out SafeProviderHandle phProvider,
     string pszProviderName,
     NCryptOpenStorageProviderFlags dwFlags = NCryptOpenStorageProviderFlags.None);
コード例 #19
0
ファイル: NCryptMockable.cs プロジェクト: ffMathy/pinvoke-1
		public SECURITY_STATUS NCryptOpenStorageProvider(
            out SafeProviderHandle phProvider,
            string pszProviderName,
            NCryptOpenStorageProviderFlags dwFlags = NCryptOpenStorageProviderFlags.None)
			=> NCryptOpenStorageProvider(out phProvider, pszProviderName, dwFlags );