using System; using System.Runtime.InteropServices; using Vanara.Extensions; using Vanara.InteropServices; using static Vanara.PInvoke.Crypt32; namespace Vanara.PInvoke { /// Methods and data types found in CryptUI.dll. public static partial class CryptUI { /// /// The PFNCFILTERPROC function is an application-defined callback function that filters the certificates that appear in the /// digital signature wizard that are displayed by the CryptUIWizDigitalSign function. /// /// A pointer to a CERT_CONTEXT structure that contains the certificate to filter. /// /// /// /// A Boolean value that specifies whether the certificate contained in the CERT_CONTEXT structure pointed to by the pCertContext /// parameter should be displayed in the digital signature wizard. /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/nc-cryptuiapi-pfncfilterproc PFNCFILTERPROC Pfncfilterproc; BOOL // Pfncfilterproc( PCCERT_CONTEXT pCertContext, BOOL *pfInitialSelectedCert, void *pvCallbackData ) {...} [PInvokeData("cryptuiapi.h", MSDNShortId = "ced0f35c-7e22-4d19-8352-0bfa37ff1a4b")] [return: MarshalAs(UnmanagedType.Bool)] public delegate bool PFNCFILTERPROC(PCCERT_CONTEXT pCertContext, [MarshalAs(UnmanagedType.Bool)] ref bool pfInitialSelectedCert, IntPtr pvCallbackData); /// Flags that can be combined to exclude columns of the display. [PInvokeData("cryptuiapi.h", MSDNShortId = "5774af1c-f2d4-4b1e-a20b-dfb57bf9aa37")] [Flags] public enum CryptUISelect { /// Do not display the ISSUEDTO information. CRYPTUI_SELECT_ISSUEDTO_COLUMN = 0x000000001, /// Do not display the ISSUEDBY information. CRYPTUI_SELECT_ISSUEDBY_COLUMN = 0x000000002, /// Do not display IntendedUse information. CRYPTUI_SELECT_INTENDEDUSE_COLUMN = 0x000000004, /// Do not display the display name information. CRYPTUI_SELECT_FRIENDLYNAME_COLUMN = 0x000000008, /// Do not display location information. CRYPTUI_SELECT_LOCATION_COLUMN = 0x000000010, /// Do not display expiration information. CRYPTUI_SELECT_EXPIRATION_COLUMN = 0x000000020, } /// Flags for . [PInvokeData("cryptuiapi.h", MSDNShortId = "7bbd58df-3a1b-4d82-9a90-7c94260a7165")] [Flags] public enum CryptUIViewCertificateFlags : uint { /// The Certification Path page is disabled. CRYPTUI_HIDE_HIERARCHYPAGE = 0x00000001, /// The Details page is disabled. CRYPTUI_HIDE_DETAILPAGE = 0x00000002, /// The user is not allowed to change the properties. CRYPTUI_DISABLE_EDITPROPERTIES = 0x00000004, /// The user is allowed to change the properties. CRYPTUI_ENABLE_EDITPROPERTIES = 0x00000008, /// The Install button is disabled. CRYPTUI_DISABLE_ADDTOSTORE = 0x00000010, /// The Install button is enabled. CRYPTUI_ENABLE_ADDTOSTORE = 0x00000020, /// The pages or buttons that allow the user to accept or decline any decision are disabled. CRYPTUI_ACCEPT_DECLINE_STYLE = 0x00000040, /// An untrusted root error is ignored. CRYPTUI_IGNORE_UNTRUSTED_ROOT = 0x00000080, /// Known trusted stores will not be used to build the chain. CRYPTUI_DONT_OPEN_STORES = 0x00000100, /// A known trusted root store will not be used to build the chain. CRYPTUI_ONLY_OPEN_ROOT_STORE = 0x00000200, /// /// Use only when viewing certificates on remote computers. If this flag is used, the first element of rghStores must be the /// handle of the root store on the remote computer. /// CRYPTUI_WARN_UNTRUSTED_ROOT = 0x00000400, /// /// Enable revocation checking with default behavior. The default behavior is to enable revocation checking of the entire /// certificate chain except the root certificate. Valid only if neither the pCryptProviderData nor the hWVTStateData union /// member is passed in. /// CRYPTUI_ENABLE_REVOCATION_CHECKING = 0x00000800, /// /// When building a certificate chain for a remote computer, warn that the chain may not be trusted on the remote computer. /// CRYPTUI_WARN_REMOTE_TRUST = 0x00001000, /// If this flag is set, the Copy to file button will be disabled on the Detail page. CRYPTUI_DISABLE_EXPORT = 0x00002000, /// /// Enable revocation checking only on the leaf certificate in the certificate chain. Valid only if neither the /// pCryptProviderData nor the hWVTStateData union member is passed in. /// CRYPTUI_ENABLE_REVOCATION_CHECK_END_CERT = 0x00004000, /// /// Enable revocation checking on each certificate in the certificate chain. Valid only if neither the pCryptProviderData nor /// the hWVTStateData union member is passed in. Note Because root certificates rarely contain information that allows /// revocation checking, it is expected that use of this option will usually result in failure of the CryptUIDlgViewCertificate /// function. The recommended option is to use CRYPTUI_ENABLE_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT. /// CRYPTUI_ENABLE_REVOCATION_CHECK_CHAIN = 0x00008000, /// /// Enable revocation checking on each certificate in the certificate chain except for the root certificate. This is the /// recommended option to use for certificate revocation checking. Valid only if neither the pCryptProviderData nor the /// hWVTStateData union member is passed in. Note This flag is equivalent to CRYPTUI_ENABLE_REVOCATION_CHECKING. /// CRYPTUI_ENABLE_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT = CRYPTUI_ENABLE_REVOCATION_CHECKING, /// Disable the HTML Help button (?) in the Certificate dialog box. CRYPTUI_DISABLE_HTMLLINK = 0x00010000, /// Disable the Issuer Statement button on the General tab of the Certificate dialog box. CRYPTUI_DISABLE_ISSUERSTATEMENT = 0x00020000, /// /// Disable online revocation checking. Set this flag to ensure that the CryptUIDlgViewCertificate function uses the local cache /// to retrieve the certificate and does not attempt to retrieve the certificate from the network. Windows Server 2008, Windows /// Vista, Windows Server 2003 and Windows XP: This flag is not supported. /// CRYPTUI_CACHE_ONLY_URL_RETRIEVAL = 0x00040000, } /// A value that indicates whether additional certificates will be included in the signature. [PInvokeData("cryptuiapi.h", MSDNShortId = "22d0bc45-0f66-4f5f-87d3-0849c4327eed")] public enum CryptUIWizAddChoice { /// No additional certificates will be included in the signature. CRYPTUI_WIZ_DIGITAL_SIGN_ADD_NONE = 0x0, /// The entire certificate chain will be included in the signature. CRYPTUI_WIZ_DIGITAL_SIGN_ADD_CHAIN = 0x00000001, /// All certificates in the certificate chain except the root will be included in the signature. CRYPTUI_WIZ_DIGITAL_SIGN_ADD_CHAIN_NO_ROOT = 0x00000002, } /// Indicates the type of the subject to export. [PInvokeData("cryptuiapi.h", MSDNShortId = "3c509bb6-d391-4b59-809c-23466c8196ea")] public enum CryptUIWizExportType { /// Export the certificate context that is specified in the pCertContext member. CRYPTUI_WIZ_EXPORT_CERT_CONTEXT = 1, /// Export the certificate trust list (CTL) context that is specified in the pCTLContext member. CRYPTUI_WIZ_EXPORT_CTL_CONTEXT = 2, /// Export the certificate revocation list (CRL) context that is specified in the pCRLContext member. CRYPTUI_WIZ_EXPORT_CRL_CONTEXT = 3, /// Export the certificate store that is specified in the hCertStore member. CRYPTUI_WIZ_EXPORT_CERT_STORE = 4, /// Export only the certificates from the certificate store that is specified in the hCertStore member. CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY = 5, /// CRYPTUI_WIZ_EXPORT_FORMAT_CRL = 6, /// CRYPTUI_WIZ_EXPORT_FORMAT_CTL = 7, } /// Contains flags that modify the behavior of . [PInvokeData("cryptuiapi.h", MSDNShortId = "1d01523e-d47b-49be-82c8-5e98f97be800")] [Flags] public enum CryptUIWizFlags : uint { /// /// This function will sign the document based on the information in the CRYPTUI_WIZ_DIGITAL_SIGN_INFO structure pointed to by /// the pDigitalSignInfo parameter without displaying any user interface. If this flag is not specified, this function will /// display a wizard to guide the user through the signing process. /// CRYPTUI_WIZ_NO_UI = 0x0001, /// /// Suppress all user interfaces generated by cryptographic service providers (CSPs). This option can be overridden by the /// CRYPTUI_WIZ_NO_UI_EXCEPT_CSP option. /// CRYPTUI_WIZ_IGNORE_NO_UI_FLAG_FOR_CSPS = 0x0002, /// /// Suppress all user interfaces except those generated by CSPs. This option overrides the /// CRYPTUI_WIZ_IGNORE_NO_UI_FLAG_FOR_CSPS option. /// CRYPTUI_WIZ_NO_UI_EXCEPT_CSP = 0x0003, /// Skip the Export Private Key page and assume that the private key is to be exported. CRYPTUI_WIZ_EXPORT_PRIVATE_KEY = 0x0100, /// Disable the Delete the private key check box in the Export File Format page. CRYPTUI_WIZ_EXPORT_NO_DELETE_PRIVATE_KEY = 0x0200, /// Allow certificates to be imported. CRYPTUI_WIZ_IMPORT_ALLOW_CERT = 0x00020000, /// Allow CRLs to be imported. CRYPTUI_WIZ_IMPORT_ALLOW_CRL = 0x00040000, /// Allow CTLs to be imported. CRYPTUI_WIZ_IMPORT_ALLOW_CTL = 0x00080000, /// Do not allow the user to change the destination certificate store represented by the hDestCertStore parameter. CRYPTUI_WIZ_IMPORT_NO_CHANGE_DEST_STORE = 0x00010000, /// /// Import the object to the certificate store for the local computer. This applies only to Personal Information Exchange (PFX) imports. /// CRYPTUI_WIZ_IMPORT_TO_LOCALMACHINE = 0x00100000, /// Import the object to the certificate store for the current user. This applies only to PFX imports. CRYPTUI_WIZ_IMPORT_TO_CURRENTUSER = 0x00200000, /// /// Import the object to a remote certificate store. Set this flag if the hDestCertStore parameter represents a remote /// certificate store. /// CRYPTUI_WIZ_IMPORT_REMOTE_DEST_STORE = 0x00400000, } /// Indicates the type of subject to import. [PInvokeData("cryptuiapi.h", MSDNShortId = "17d932e3-05ea-4ed0-9f88-fbb674b6b070")] public enum CryptUIWizImportType { /// Import the certificate stored in the file referenced in the pwszFileName member. CRYPTUI_WIZ_IMPORT_SUBJECT_FILE = 1, /// Import the certificate referenced in the pCertContext member. CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_CONTEXT = 2, /// Import the CTL referenced in the pCTLContext member. CRYPTUI_WIZ_IMPORT_SUBJECT_CTL_CONTEXT = 3, /// Import the CRL referenced in the pCRLContext member. CRYPTUI_WIZ_IMPORT_SUBJECT_CRL_CONTEXT = 4, /// Import the certificate store referenced in the hCertStore member. CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_STORE = 5, } /// Specifies the type of entity that contains the certificates. [PInvokeData("cryptuiapi.h", MSDNShortId = "0316ed0b-d4e5-4102-9ab0-637e96c7d9f5")] [Flags] public enum CryptUIWizPVKChoice { /// The entity is a PVK file. CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE = 0x01, /// The entity is a PVK provider. CRYPTUI_WIZ_DIGITAL_SIGN_PVK_PROV = 0x02, } /// A value that specifies the location of the certificate that is used to sign the entity. [PInvokeData("cryptuiapi.h", MSDNShortId = "22d0bc45-0f66-4f5f-87d3-0849c4327eed")] public enum CryptUIWizSignLoc { /// The certificates in the My store are used. CRYPTUI_WIZ_DIGITAL_SIGN_USE_MY_STORE = 0x0, /// The certificate is contained in the CERT_CONTEXT structure pointed to by the pSigningCertContext member. CRYPTUI_WIZ_DIGITAL_SIGN_CERT = 0x01, /// /// The certificate is contained in the certificate store contained in the CRYPTUI_WIZ_DIGITAL_SIGN_STORE_INFO structure pointed /// to by the pSigningCertStore member. /// CRYPTUI_WIZ_DIGITAL_SIGN_STORE = 0x02, /// /// The certificate is contained in the PVK file contained in the CRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO structure pointed to by /// the pSigningCertPvkInfo member. /// CRYPTUI_WIZ_DIGITAL_SIGN_PVK = 0x03, } /// A value that indicates the type of the signature. [PInvokeData("cryptuiapi.h", MSDNShortId = "e061aac4-8c9f-4282-a8f8-bc0c5a10e566")] [Flags] public enum CryptUIWizSigType { /// The signature is a commercial signature. CRYPTUI_WIZ_DIGITAL_SIGN_COMMERCIAL = 0x01, /// The signature is a personal signature. CRYPTUI_WIZ_DIGITAL_SIGN_INDIVIDUAL = 0x02, } /// A value that indicates the entity that is to be signed. [PInvokeData("cryptuiapi.h", MSDNShortId = "22d0bc45-0f66-4f5f-87d3-0849c4327eed")] public enum CryptUIWizToSign { /// The user will be prompted for a file to sign. CRYPTUI_WIZ_DIGITAL_SIGN_SUBJECT_PROMPT = 0, /// The memory BLOB specified by the pSignBlobInfo member is to be signed. CRYPTUI_WIZ_DIGITAL_SIGN_SUBJECT_FILE = 0x01, /// The file specified by the pwszFileName member is to be signed. CRYPTUI_WIZ_DIGITAL_SIGN_SUBJECT_BLOB = 0x02, } /// /// The CertSelectionGetSerializedBlob function is a helper function used to retrieve a serialized certificate BLOB from a /// CERT_SELECTUI_INPUT structure. /// /// /// A pointer to a CERT_SELECTUI_INPUT structure that contains the certificate store and certificate context chain information. /// /// The address of a pointer to a buffer that receives the serialized certificates BLOB. /// /// A pointer to a ULONG to receive the size, in bytes, of the BLOB received in the buffer pointed to by the ppOutBuffer parameter. /// /// /// If the function succeeds, the function returns S_OK. /// /// If the function fails, it returns an HRESULT value that indicates the error. If both hStore and prgpChain /// parameters are not NULL, return E_INVALIDARG. For a list of common error codes, see Common HRESULT Values. /// /// /// /// /// The returned serialized BLOB is passed to the CredUIPromptForWindowsCredentials function in the pvInAuthBuffer parameter to /// allow a user to select a certificate by using the credential selection UI. /// /// /// The certificates that are serialized in the BLOB returned in the buffer pointed to by the ppOutBuffer parameter of this function /// are dependent on the values of the hStore and prgpChain members of the CERT_SELECTUI_INPUT structure. /// /// /// /// hStore /// prgpChain /// Certificates serialized /// /// /// NULL /// not NULL /// The certificates pointed to by the prgpChain member are serialized. /// /// /// not NULL /// NULL /// The certificates specified by the hStore member are serialized. /// /// /// NULL /// NULL /// An empty BLOB is returned. /// /// /// not NULL /// not NULL /// The call fails and the function returns E_INVALIDARG. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/nf-cryptuiapi-certselectiongetserializedblob HRESULT // CertSelectionGetSerializedBlob( PCERT_SELECTUI_INPUT pcsi, void **ppOutBuffer, ULONG *pulOutBufferSize ); [DllImport(Lib.CryptUI, SetLastError = false, ExactSpelling = true)] [PInvokeData("cryptuiapi.h", MSDNShortId = "6c3240f7-5121-401d-a4d4-df3055cb301a")] public static extern HRESULT CertSelectionGetSerializedBlob(in CERT_SELECTUI_INPUT pcsi, out IntPtr ppOutBuffer, out uint pulOutBufferSize); /// The CryptUIDlgCertMgr function displays a dialog box that allows the user to manage certificates. /// /// A pointer to a CRYPTUI_CERT_MGR_STRUCT structure that contains information about how to create the dialog box. /// /// The return value is TRUE if the function succeeds; otherwise, FALSE. // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/nf-cryptuiapi-cryptuidlgcertmgr BOOL CryptUIDlgCertMgr( // PCCRYPTUI_CERT_MGR_STRUCT pCryptUICertMgr ); [DllImport(Lib.CryptUI, SetLastError = false, ExactSpelling = true)] [PInvokeData("cryptuiapi.h", MSDNShortId = "8d94694e-1724-42aa-99bb-6ed2c6d3bc0e")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CryptUIDlgCertMgr(in CRYPTUI_CERT_MGR_STRUCT pCryptUICertMgr); /// /// The CryptUIDlgSelectCertificateFromStore function displays a dialog box that allows the selection of a certificate from a /// specified store. /// /// Handle of the certificate store to be searched. /// Handle of the window for the display. If NULL, defaults to the desktop window. /// /// String used as the title of the dialog box. If NULL, the default title, "Select Certificate," is used. /// /// /// Text statement in the selection dialog box. If NULL, the default phrase, "Select a certificate you want to use," is used. /// /// /// Flags that can be combined to exclude columns of the display. /// /// /// Value /// Meaning /// /// /// CRYPTUI_SELECT_ISSUEDTO_COLUMN /// Do not display the ISSUEDTO information. /// /// /// CRYPTUI_SELECT_ISSUEDBY_COLUMN /// Do not display the ISSUEDBY information. /// /// /// CRYPTUI_SELECT_INTENDEDUSE_COLUMN /// Do not display IntendedUse information. /// /// /// CRYPTUI_SELECT_FRIENDLYNAME_COLUMN /// Do not display the display name information. /// /// /// CRYPTUI_SELECT_LOCATION_COLUMN /// Do not display location information. /// /// /// CRYPTUI_SELECT_EXPIRATION_COLUMN /// Do not display expiration information. /// /// /// /// Currently not used and should be set to 0. /// Reserved for future use. /// /// Returns a pointer to the selected certificate context. If no certificate was selected, NULL is returned. When you have /// finished using the certificate, free the certificate context by calling the CertFreeCertificateContext function. /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/nf-cryptuiapi-cryptuidlgselectcertificatefromstore PCCERT_CONTEXT // CryptUIDlgSelectCertificateFromStore( HCERTSTORE hCertStore, HWND hwnd, LPCWSTR pwszTitle, LPCWSTR pwszDisplayString, DWORD // dwDontUseColumn, DWORD dwFlags, void *pvReserved ); [DllImport(Lib.CryptUI, SetLastError = false, ExactSpelling = true)] [PInvokeData("cryptuiapi.h", MSDNShortId = "5774af1c-f2d4-4b1e-a20b-dfb57bf9aa37")] public static extern SafePCCERT_CONTEXT CryptUIDlgSelectCertificateFromStore([In] HCERTSTORE hCertStore, [In, Optional] HWND hwnd, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pwszTitle, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pwszDisplayString, CryptUISelect dwDontUseColumn, uint dwFlags = 0, IntPtr pvReserved = default); /// The CryptUIDlgViewCertificate function presents a dialog box that displays a specified certificate. /// /// A pointer to a CRYPTUI_VIEWCERTIFICATE_STRUCT structure that contains information about the certificate to view. /// /// Indicates whether any certificate properties were modified by the caller. /// /// If the function succeeds, the return value is nonzero ( TRUE). /// /// If the function fails, the return value is zero ( FALSE). For extended error information, call the GetLastError function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/nf-cryptuiapi-cryptuidlgviewcertificatea BOOL // CryptUIDlgViewCertificateA( PCCRYPTUI_VIEWCERTIFICATE_STRUCTA pCertViewInfo, BOOL *pfPropertiesChanged ); [DllImport(Lib.CryptUI, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("cryptuiapi.h", MSDNShortId = "5107ff22-78c4-4005-80af-ff45781da6c7")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CryptUIDlgViewCertificate(in CRYPTUI_VIEWCERTIFICATE_STRUCT pCertViewInfo, [MarshalAs(UnmanagedType.Bool)] out bool pfPropertiesChanged); /// The CryptUIDlgViewContext function displays a certificate, CTL, or CRL context. /// /// /// DWORD indicating whether pvContext is a pointer to a certificate, a CRL, or a CTL context as indicated in the following table. /// /// /// /// Value /// Meaning /// /// /// CERT_STORE_CERTIFICATE_CONTEXT /// PCCERT_CONTEXT /// /// /// CERT_STORE_CRL_CONTEXT /// PCCRL_CONTEXT /// /// /// CERT_STORE_CTL_CONTEXT /// PCCTL_CONTEXT /// /// /// /// A pointer to a certificate, CRL, or CTL context to be displayed. /// Handle of the window for the display. If NULL, the display defaults to the desktop window. /// Display title string. If NULL, the default context type is used as the title. /// Currently not used and should be set to 0. /// Reserved for future use. /// This function returns TRUE on success and FALSE on failure. // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/nf-cryptuiapi-cryptuidlgviewcontext BOOL CryptUIDlgViewContext( // DWORD dwContextType, const void *pvContext, HWND hwnd, LPCWSTR pwszTitle, DWORD dwFlags, void *pvReserved ); [DllImport(Lib.CryptUI, SetLastError = false, ExactSpelling = true)] [PInvokeData("cryptuiapi.h", MSDNShortId = "d4b8f01b-7c3e-4286-bc37-d5ec4a1e1c2f")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CryptUIDlgViewContext(CertStoreContextType dwContextType, [In] IntPtr pvContext, [In, Optional] HWND hwnd, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pwszTitle, uint dwFlags = 0, IntPtr pvReserved = default); /// /// /// [The CryptUIWizDigitalSign function is available for use in the operating systems specified in the Requirements section. /// It may be altered or unavailable in subsequent versions.] /// /// /// The CryptUIWizDigitalSign function digitally signs a document or BLOB. The document or BLOB can be signed with or without /// user interaction. /// /// /// /// Contains flags that modify the behavior of the function. This can be zero or the following value. /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_NO_UI 0x0001 /// /// This function will sign the document based on the information in the CRYPTUI_WIZ_DIGITAL_SIGN_INFO structure pointed to by the /// pDigitalSignInfo parameter without displaying any user interface. If this flag is not specified, this function will display a /// wizard to guide the user through the signing process. /// /// /// /// /// /// The handle of the window to use as the parent of the dialog box that this function creates. This parameter is ignored if the /// CRYPTUI_WIZ_NO_UI flag is set in dwFlags. /// /// /// A pointer to a null-terminated Unicode string that contains the title to use in the dialog box that this function creates. This /// parameter is ignored if the CRYPT_WIZ_NO_UI flag is set in dwFlags. If this parameter is NULL, a default title is used. /// /// /// A pointer to a CRYPTUI_WIZ_DIGITAL_SIGN_INFO structure that contains information about the signing process. /// /// /// A pointer to a CRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT structure pointer that receives the signed BLOB. When you have finished using /// this structure, you must free the memory by passing this pointer to the CryptUIWizFreeDigitalSignContext function. This /// parameter can be NULL if the signed BLOB is not needed. /// /// /// If the function succeeds, the function returns nonzero. /// If the function fails, it returns zero. /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/nf-cryptuiapi-cryptuiwizdigitalsign BOOL CryptUIWizDigitalSign( // DWORD dwFlags, HWND hwndParent, LPCWSTR pwszWizardTitle, PCCRYPTUI_WIZ_DIGITAL_SIGN_INFO pDigitalSignInfo, // PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT *ppSignContext ); [DllImport(Lib.CryptUI, SetLastError = false, ExactSpelling = true)] [PInvokeData("cryptuiapi.h", MSDNShortId = "1d01523e-d47b-49be-82c8-5e98f97be800")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CryptUIWizDigitalSign(CryptUIWizFlags dwFlags, [In, Optional] HWND hwndParent, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pwszWizardTitle, in CRYPTUI_WIZ_DIGITAL_SIGN_INFO pDigitalSignInfo, out SafePCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT ppSignContext); /// /// The CryptUIWizExport function exports a certificate, a certificate trust list (CTL), a certificate revocation list (CRL), /// or a certificate store to a file. The export can be performed with or without user interaction. /// /// /// /// Contains flags that modify the behavior of the function. This can be zero or a combination of one or more of the following values. /// /// /// Note Except for CRYPTUI_WIZ_NO_UI, none of the following constants are defined in a published header file. To use /// these constants, you must define them by using the specified values. /// /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_NO_UI 0x0001 /// /// This function will perform the export based on the information in the CRYPTUI_WIZ_EXPORT_INFO structure pointed to by /// pExportInfo without displaying any user interface. If this flag is not specified, this function will display a wizard to guide /// the user through the export process. /// /// /// /// CRYPTUI_WIZ_IGNORE_NO_UI_FLAG_FOR_CSPS 0x0002 /// /// Suppress all user interfaces generated by cryptographic service providers (CSPs). This option can be overridden by the /// CRYPTUI_WIZ_NO_UI_EXCEPT_CSP option. /// /// /// /// CRYPTUI_WIZ_NO_UI_EXCEPT_CSP 0x0003 /// /// Suppress all user interfaces except those generated by CSPs. This option overrides the CRYPTUI_WIZ_IGNORE_NO_UI_FLAG_FOR_CSPS option. /// /// /// /// CRYPTUI_WIZ_EXPORT_PRIVATE_KEY 0x0100 /// Skip the Export Private Key page and assume that the private key is to be exported. /// /// /// CRYPTUI_WIZ_EXPORT_NO_DELETE_PRIVATE_KEY 0x0200 /// Disable the Delete the private key check box in the Export File Format page. /// /// /// /// /// The handle of the window to use as the parent of the dialog box that this function creates. This parameter is ignored if the /// CRYPT_WIZ_NO_UI flag is set in dwFlags. /// /// /// A pointer to a null-terminated Unicode string that contains the title to use in the dialog box that this function creates. This /// parameter is ignored if the CRYPT_WIZ_NO_UI flag is set in dwFlags. /// /// /// A pointer to a CRYPTUI_WIZ_EXPORT_INFO structure that contains information about producing the export wizard. /// /// /// /// If the dwSubjectChoice member of the CRYPTUI_WIZ_EXPORT_INFO structure that pExportInfo references is /// CRYPTUI_WIZ_EXPORT_CERT_CONTEXT, and if the CRYPTUI_WIZ_NO_UI flag is set in dwFlags, this parameter is a pointer /// to a CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO structure. /// /// /// If the CRYPTUI_WIZ_NO_UI flag is not set in dwFlags, this parameter is optional and can be NULL. If this parameter /// is not NULL, the CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO structure contains the values that are displayed to the user as the /// default choices. /// /// /// /// If the function succeeds, the function returns nonzero. /// If the function fails, it returns zero. For extended error information, call the GetLastError function. /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/nf-cryptuiapi-cryptuiwizexport BOOL CryptUIWizExport( DWORD // dwFlags, HWND hwndParent, LPCWSTR pwszWizardTitle, PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo, void *pvoid ); [DllImport(Lib.CryptUI, SetLastError = true, ExactSpelling = true)] [PInvokeData("cryptuiapi.h", MSDNShortId = "62537d51-c761-4180-b857-58c819ea66aa")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CryptUIWizExport(CryptUIWizFlags dwFlags, [In, Optional] HWND hwndParent, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pwszWizardTitle, in CRYPTUI_WIZ_EXPORT_INFO pExportInfo, [In, Optional] IntPtr pvoid); /// /// The CryptUIWizFreeDigitalSignContext function frees the CRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT structure allocated by the /// CryptUIWizDigitalSign function. /// /// A pointer to the CRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT structure to be freed. /// /// If the function succeeds, the function returns nonzero. /// If the function fails, it returns zero. /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/nf-cryptuiapi-cryptuiwizfreedigitalsigncontext BOOL // CryptUIWizFreeDigitalSignContext( PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT pSignContext ); [DllImport(Lib.CryptUI, SetLastError = false, ExactSpelling = true)] [PInvokeData("cryptuiapi.h", MSDNShortId = "039615ee-0485-4698-944f-23359253767a")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CryptUIWizFreeDigitalSignContext(PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT pSignContext); /// /// The function imports a certificate, a certificate trust list (CTL), a certificate revocation list (CRL), or a certificate store /// to a certificate store. The import can be performed with or without user interaction. /// /// /// /// Contains flags that modify the behavior of the function. This can be zero or a combination of one or more of the following values. /// /// /// Note Except for CRYPTUI_WIZ_NO_UI, none of the following constants are defined in a published header file. To use /// these constants, you must define them by using the specified values. /// /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_NO_UI 0x0001 /// /// This function will perform the import based on the information in the CRYPTUI_WIZ_IMPORT_SRC_INFO structure pointed to by /// pImportSrc into the store specified by hDestCertStore without displaying any user interface. If this flag is not specified, this /// function will display a wizard to guide the user through the import process. Beginning with Windows 8 and Windows Server 2012, /// if you set this flag and are importing a certificate from a PFX BLOB that was protected to an Active Directory (AD) principal, /// and the current user, as part of that principal, has permission to decrypt the password embedded in the PFX packet, the /// importation will succeed without requiring that a password be set in the CRYPTUI_WIZ_IMPORT_SRC_INFO structure. For more /// information about protecting PFX to an AD principal, see the pvPara parameter and the PKCS12_PROTECT_TO_DOMAIN_SIDS flag of the /// PFXExportCertStoreEx function. /// /// /// /// CRYPTUI_WIZ_IGNORE_NO_UI_FLAG_FOR_CSPS 0x0002 /// /// Suppress all user interfaces generated by cryptographic service providers (CSPs). This option can be overridden by the /// CRYPTUI_WIZ_NO_UI_EXCEPT_CSP option. /// /// /// /// CRYPTUI_WIZ_NO_UI_EXCEPT_CSP 0x0003 /// /// Suppress all user interfaces except those generated by CSPs. This option overrides the CRYPTUI_WIZ_IGNORE_NO_UI_FLAG_FOR_CSPS option. /// /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CERT 0x00020000 /// Allow certificates to be imported. /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CRL 0x00040000 /// Allow CRLs to be imported. /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CTL 0x00080000 /// Allow CTLs to be imported. /// /// /// CRYPTUI_WIZ_IMPORT_NO_CHANGE_DEST_STORE 0x00010000 /// Do not allow the user to change the destination certificate store represented by the hDestCertStore parameter. /// /// /// CRYPTUI_WIZ_IMPORT_TO_LOCALMACHINE 0x00100000 /// /// Import the object to the certificate store for the local computer. This applies only to Personal Information Exchange (PFX) imports. /// /// /// /// CRYPTUI_WIZ_IMPORT_TO_CURRENTUSER 0x00200000 /// Import the object to the certificate store for the current user. This applies only to PFX imports. /// /// /// CRYPTUI_WIZ_IMPORT_REMOTE_DEST_STORE 0x00400000 /// /// Import the object to a remote certificate store. Set this flag if the hDestCertStore parameter represents a remote certificate store. /// /// /// /// /// /// The handle of the window to use as the parent of the dialog box that this function creates. This parameter is ignored if the /// CRYPTUI_WIZ_NO_UI flag is set in dwFlags. /// /// /// A pointer to a null-terminated Unicode string that contains the title to use in the dialog box that this function creates. This /// parameter is ignored if the CRYPTUI_WIZ_NO_UI flag is set in dwFlags. /// /// /// A pointer to a CRYPTUI_WIZ_IMPORT_SRC_INFO structure that contains information about the object to import. This parameter is /// required if CRYPTUI_WIZ_NO_UI is set in dwFlags and is optional otherwise. /// /// /// A handle to the certificate store to import to. If this parameter is NULL and the CRYPTUI_WIZ_NO_UI flag is not /// set in dwFlags, the wizard will prompt the user to select a certificate store. /// /// /// If the function succeeds, the function returns nonzero. /// If the function fails, it returns zero. For extended error information, call the GetLastError function. /// /// /// If none of following three flags are set in dwFlags, import of any type of content is allowed: /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CERT /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CRL /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CTL /// /// /// /// The CRYPTUI_WIZ_IMPORT_TO_LOCALMACHINE and CRYPTUI_WIZ_IMPORT_TO_CURRENTUSER flags are used to force the content /// of a PFX BLOB into either the local machine store or the current user store. If neither of these flags are set and /// hDestCertStore is NULL: /// /// /// /// The private key in the PFX BLOB will be forced to be imported into the current user store. /// /// /// /// And if CRYPTUI_WIZ_NO_UI is not set, the wizard prompts the user to select a certificate store from among the current /// user certificate stores. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/nf-cryptuiapi-cryptuiwizimport BOOL CryptUIWizImport( DWORD // dwFlags, HWND hwndParent, LPCWSTR pwszWizardTitle, PCCRYPTUI_WIZ_IMPORT_SRC_INFO pImportSrc, HCERTSTORE hDestCertStore ); [DllImport(Lib.CryptUI, SetLastError = true, ExactSpelling = true)] [PInvokeData("cryptuiapi.h", MSDNShortId = "6b2b9c89-229a-4626-a8b4-fe2b7cc0af86")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CryptUIWizImport(CryptUIWizFlags dwFlags, [In, Optional] HWND hwndParent, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pwszWizardTitle, in CRYPTUI_WIZ_IMPORT_SRC_INFO pImportSrc, [In, Optional] HCERTSTORE hDestCertStore); /// /// The function imports a certificate, a certificate trust list (CTL), a certificate revocation list (CRL), or a certificate store /// to a certificate store. The import can be performed with or without user interaction. /// /// /// /// Contains flags that modify the behavior of the function. This can be zero or a combination of one or more of the following values. /// /// /// Note Except for CRYPTUI_WIZ_NO_UI, none of the following constants are defined in a published header file. To use /// these constants, you must define them by using the specified values. /// /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_NO_UI 0x0001 /// /// This function will perform the import based on the information in the CRYPTUI_WIZ_IMPORT_SRC_INFO structure pointed to by /// pImportSrc into the store specified by hDestCertStore without displaying any user interface. If this flag is not specified, this /// function will display a wizard to guide the user through the import process. Beginning with Windows 8 and Windows Server 2012, /// if you set this flag and are importing a certificate from a PFX BLOB that was protected to an Active Directory (AD) principal, /// and the current user, as part of that principal, has permission to decrypt the password embedded in the PFX packet, the /// importation will succeed without requiring that a password be set in the CRYPTUI_WIZ_IMPORT_SRC_INFO structure. For more /// information about protecting PFX to an AD principal, see the pvPara parameter and the PKCS12_PROTECT_TO_DOMAIN_SIDS flag of the /// PFXExportCertStoreEx function. /// /// /// /// CRYPTUI_WIZ_IGNORE_NO_UI_FLAG_FOR_CSPS 0x0002 /// /// Suppress all user interfaces generated by cryptographic service providers (CSPs). This option can be overridden by the /// CRYPTUI_WIZ_NO_UI_EXCEPT_CSP option. /// /// /// /// CRYPTUI_WIZ_NO_UI_EXCEPT_CSP 0x0003 /// /// Suppress all user interfaces except those generated by CSPs. This option overrides the CRYPTUI_WIZ_IGNORE_NO_UI_FLAG_FOR_CSPS option. /// /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CERT 0x00020000 /// Allow certificates to be imported. /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CRL 0x00040000 /// Allow CRLs to be imported. /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CTL 0x00080000 /// Allow CTLs to be imported. /// /// /// CRYPTUI_WIZ_IMPORT_NO_CHANGE_DEST_STORE 0x00010000 /// Do not allow the user to change the destination certificate store represented by the hDestCertStore parameter. /// /// /// CRYPTUI_WIZ_IMPORT_TO_LOCALMACHINE 0x00100000 /// /// Import the object to the certificate store for the local computer. This applies only to Personal Information Exchange (PFX) imports. /// /// /// /// CRYPTUI_WIZ_IMPORT_TO_CURRENTUSER 0x00200000 /// Import the object to the certificate store for the current user. This applies only to PFX imports. /// /// /// CRYPTUI_WIZ_IMPORT_REMOTE_DEST_STORE 0x00400000 /// /// Import the object to a remote certificate store. Set this flag if the hDestCertStore parameter represents a remote certificate store. /// /// /// /// /// /// The handle of the window to use as the parent of the dialog box that this function creates. This parameter is ignored if the /// CRYPTUI_WIZ_NO_UI flag is set in dwFlags. /// /// /// A pointer to a null-terminated Unicode string that contains the title to use in the dialog box that this function creates. This /// parameter is ignored if the CRYPTUI_WIZ_NO_UI flag is set in dwFlags. /// /// /// A pointer to a CRYPTUI_WIZ_IMPORT_SRC_INFO structure that contains information about the object to import. This parameter is /// required if CRYPTUI_WIZ_NO_UI is set in dwFlags and is optional otherwise. /// /// /// A handle to the certificate store to import to. If this parameter is NULL and the CRYPTUI_WIZ_NO_UI flag is not /// set in dwFlags, the wizard will prompt the user to select a certificate store. /// /// /// If the function succeeds, the function returns nonzero. /// If the function fails, it returns zero. For extended error information, call the GetLastError function. /// /// /// If none of following three flags are set in dwFlags, import of any type of content is allowed: /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CERT /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CRL /// /// /// CRYPTUI_WIZ_IMPORT_ALLOW_CTL /// /// /// /// The CRYPTUI_WIZ_IMPORT_TO_LOCALMACHINE and CRYPTUI_WIZ_IMPORT_TO_CURRENTUSER flags are used to force the content /// of a PFX BLOB into either the local machine store or the current user store. If neither of these flags are set and /// hDestCertStore is NULL: /// /// /// /// The private key in the PFX BLOB will be forced to be imported into the current user store. /// /// /// /// And if CRYPTUI_WIZ_NO_UI is not set, the wizard prompts the user to select a certificate store from among the current /// user certificate stores. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/nf-cryptuiapi-cryptuiwizimport BOOL CryptUIWizImport( DWORD // dwFlags, HWND hwndParent, LPCWSTR pwszWizardTitle, PCCRYPTUI_WIZ_IMPORT_SRC_INFO pImportSrc, HCERTSTORE hDestCertStore ); [DllImport(Lib.CryptUI, SetLastError = true, ExactSpelling = true)] [PInvokeData("cryptuiapi.h", MSDNShortId = "6b2b9c89-229a-4626-a8b4-fe2b7cc0af86")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CryptUIWizImport(CryptUIWizFlags dwFlags, [In, Optional] HWND hwndParent, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pwszWizardTitle, [In, Optional] IntPtr pImportSrc, [In, Optional] HCERTSTORE hDestCertStore); /// /// The CERT_SELECTUI_INPUT structure is used by the CertSelectionGetSerializedBlob function to serialize the certificates /// contained in a store or an array of certificate chains. The returned serialized BLOB can be passed to the /// CredUIPromptForWindowsCredentials function. /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cert_selectui_input typedef struct { HCERTSTORE // hStore; PCCERT_CHAIN_CONTEXT *prgpChain; DWORD cChain; } CERT_SELECTUI_INPUT, *PCERT_SELECTUI_INPUT; [PInvokeData("cryptuiapi.h", MSDNShortId = "8953cddd-86b6-4781-8dca-b5fd3d298bc8")] [StructLayout(LayoutKind.Sequential)] public struct CERT_SELECTUI_INPUT { /// /// The handle of a certificate store created by the caller. The store contains the set of application preselected certificates. /// public HCERTSTORE hStore; /// /// An array of pointers to CERT_CHAIN_CONTEXT structures. Applications provision this array by preselecting certificate chains /// using the CertSelectCertificateChains function. /// public IntPtr prgpChain; /// The number of CERT_CHAIN_CONTEXT structures that are in the array pointed to by the prgpChain member. public uint cChain; /// Gets the array of pointers to CERT_CHAIN_CONTEXT structures. public PCCERT_CHAIN_CONTEXT[] GetChain() => prgpChain.ToArray((int)cChain); } /// The CRYPTUI_CERT_MGR_STRUCT structure contains information about a certificate manager dialog box. // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_cert_mgr_struct typedef struct // _CRYPTUI_CERT_MGR_STRUCT { DWORD dwSize; HWND hwndParent; DWORD dwFlags; LPCWSTR pwszTitle; LPCSTR pszInitUsageOID; } // CRYPTUI_CERT_MGR_STRUCT, *PCRYPTUI_CERT_MGR_STRUCT; [PInvokeData("cryptuiapi.h", MSDNShortId = "e6c24d16-0ae2-443c-8971-2d7da3aae963")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_CERT_MGR_STRUCT { /// The size, in bytes, of the structure. This value must be set to . public uint dwSize; /// Handle of the parent window of the dialog box. public HWND hwndParent; /// Reserved. This value must be set to zero. public uint dwFlags; /// Title of the dialog box. [MarshalAs(UnmanagedType.LPWStr)] public string pwszTitle; /// /// Enhanced key usage object identifier (OID) of the certificates that will initially appear in the dialog box. The default /// value is NULL, which displays all certificates. /// public StrPtrAnsi pszInitUsageOID; } /// /// The CRYPTUI_INITDIALOG_STRUCT structure supports the CRYPTUI_VIEWCERTIFICATE_STRUCT structure. It is passed as the lParam /// in the WM_INITDIALOG call to each property sheet that is in the rgPropSheetPages array of the /// CRYPTUI_VIEWCERTIFICATE_STRUCT structure. The CRYPTUI_VIEWCERTIFICATE_STRUCT structure is used in the /// CryptUIDlgViewCertificate function. /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_initdialog_struct typedef struct // tagCRYPTUI_INITDIALOG_STRUCT { LPARAM lParam; PCCERT_CONTEXT pCertContext; } CRYPTUI_INITDIALOG_STRUCT, *PCRYPTUI_INITDIALOG_STRUCT; [PInvokeData("cryptuiapi.h", MSDNShortId = "c6335c02-3b3e-45e2-bb58-b7213aea500b")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_INITDIALOG_STRUCT { /// The lParam in the PROPSHEETPAGE structure. public IntPtr lParam; /// A pointer to the CERT_CONTEXT structure for the certificate that CryptUIDlgViewCertificate is displaying. public PCCERT_CONTEXT pCertContext; } /// /// The CRYPTUI_VIEWCERTIFICATE_STRUCT structure contains information about a certificate to view. This structure is used in /// the CryptUIDlgViewCertificate function. /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_viewcertificate_structa typedef struct // tagCRYPTUI_VIEWCERTIFICATE_STRUCTA { DWORD dwSize; HWND hwndParent; DWORD dwFlags; LPCSTR szTitle; PCCERT_CONTEXT pCertContext; // LPCSTR *rgszPurposes; DWORD cPurposes; union { CRYPT_PROVIDER_DATA const *pCryptProviderData; HANDLE hWVTStateData; }; BOOL // fpCryptProviderDataTrustedUsage; DWORD idxSigner; DWORD idxCert; BOOL fCounterSigner; DWORD idxCounterSigner; DWORD cStores; // HCERTSTORE *rghStores; DWORD cPropSheetPages; LPCPROPSHEETPAGEA rgPropSheetPages; DWORD nStartPage; } // CRYPTUI_VIEWCERTIFICATE_STRUCTA, *PCRYPTUI_VIEWCERTIFICATE_STRUCTA; [PInvokeData("cryptuiapi.h", MSDNShortId = "7bbd58df-3a1b-4d82-9a90-7c94260a7165")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct CRYPTUI_VIEWCERTIFICATE_STRUCT { /// The size, in bytes, of the CRYPTUI_VIEWCERTIFICATE_STRUCT structure. public uint dwSize; /// A handle to the window that is the parent of the dialog box produced by CryptUIDlgViewCertificate. public HWND hwndParent; /// /// This member can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// CRYPTUI_HIDE_HIERARCHYPAGE /// The Certification Path page is disabled. /// /// /// CRYPTUI_HIDE_DETAILPAGE /// The Details page is disabled. /// /// /// CRYPTUI_DISABLE_EDITPROPERTIES /// The user is not allowed to change the properties. /// /// /// CRYPTUI_ENABLE_EDITPROPERTIES /// The user is allowed to change the properties. /// /// /// CRYPTUI_DISABLE_ADDTOSTORE /// The Install button is disabled. /// /// /// CRYPTUI_ENABLE_ADDTOSTORE /// The Install button is enabled. /// /// /// CRYPTUI_ACCEPT_DECLINE_STYLE /// The pages or buttons that allow the user to accept or decline any decision are disabled. /// /// /// CRYPTUI_IGNORE_UNTRUSTED_ROOT /// An untrusted root error is ignored. /// /// /// CRYPTUI_DONT_OPEN_STORES /// Known trusted stores will not be used to build the chain. /// /// /// CRYPTUI_ONLY_OPEN_ROOT_STORE /// A known trusted root store will not be used to build the chain. /// /// /// CRYPTUI_WARN_UNTRUSTED_ROOT /// /// Use only when viewing certificates on remote computers. If this flag is used, the first element of rghStores must be the /// handle of the root store on the remote computer. /// /// /// /// CRYPTUI_ENABLE_REVOCATION_CHECKING /// /// Enable revocation checking with default behavior. The default behavior is to enable revocation checking of the entire /// certificate chain except the root certificate. Valid only if neither the pCryptProviderData nor the hWVTStateData union /// member is passed in. /// /// /// /// CRYPTUI_WARN_REMOTE_TRUST /// When building a certificate chain for a remote computer, warn that the chain may not be trusted on the remote computer. /// /// /// CRYPTUI_DISABLE_EXPORT /// If this flag is set, the Copy to file button will be disabled on the Detail page. /// /// /// CRYPTUI_ENABLE_REVOCATION_CHECK_END_CERT /// /// Enable revocation checking only on the leaf certificate in the certificate chain. Valid only if neither the /// pCryptProviderData nor the hWVTStateData union member is passed in. /// /// /// /// CRYPTUI_ENABLE_REVOCATION_CHECK_CHAIN /// /// Enable revocation checking on each certificate in the certificate chain. Valid only if neither the pCryptProviderData nor /// the hWVTStateData union member is passed in. Note Because root certificates rarely contain information that allows /// revocation checking, it is expected that use of this option will usually result in failure of the CryptUIDlgViewCertificate /// function. The recommended option is to use CRYPTUI_ENABLE_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT. /// /// /// /// CRYPTUI_ENABLE_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT /// /// Enable revocation checking on each certificate in the certificate chain except for the root certificate. This is the /// recommended option to use for certificate revocation checking. Valid only if neither the pCryptProviderData nor the /// hWVTStateData union member is passed in. Note This flag is equivalent to CRYPTUI_ENABLE_REVOCATION_CHECKING. /// /// /// /// CRYPTUI_DISABLE_HTMLLINK /// Disable the HTML Help button (?) in the Certificate dialog box. /// /// /// CRYPTUI_DISABLE_ISSUERSTATEMENT /// Disable the Issuer Statement button on the General tab of the Certificate dialog box. /// /// /// CRYPTUI_CACHE_ONLY_URL_RETRIEVAL /// /// Disable online revocation checking. Set this flag to ensure that the CryptUIDlgViewCertificate function uses the local cache /// to retrieve the certificate and does not attempt to retrieve the certificate from the network. Windows Server 2008, Windows /// Vista, Windows Server 2003 and Windows XP: This flag is not supported. /// /// /// /// public CryptUIViewCertificateFlags dwFlags; /// A pointer to a null-terminated string that contains the title for the window. [MarshalAs(UnmanagedType.LPTStr)] public string szTitle; /// A pointer to the CERT_CONTEXT structure that contains the certificate context to display. public PCCERT_CONTEXT pCertContext; /// /// An array of pointers to null-terminated strings that contain the purposes for which this certificate will be validated. /// public IntPtr rgszPurposes; /// The number of purposes in the rgszPurposes array. public uint cPurposes; /// /// If the WinVerifyTrust function has already been called for the certificate and the WTHelperProvDataFromStateData function /// was also called, pass in a pointer to the state structure that was acquired from the call to /// WTHelperProvDataFromStateData. If pCryptProviderData is set, fpCryptProviderDataTrustedUsage, /// idxSigner, idxCert, and fCounterSignature must also be set. /// OR /// /// If WinVerifyTrust has already been called for the certificate and WTHelperProvDataFromStateData was not called, pass in the /// hWVTStateData member of the WINTRUST_DATA structure. If hWVTStateData is set, /// fpCryptProviderDataTrustedUsage, idxSigner, idxCert, and fCounterSignature must also be set. /// /// public IntPtr pData; /// If WinVerifyTrust was called, this is the result of whether the certificate was trusted. [MarshalAs(UnmanagedType.Bool)] public bool fpCryptProviderDataTrustedUsage; /// The index of the signer to view. public uint idxSigner; /// /// The index of the certificate that is being viewed within the signer chain. The certificate context of this cert must match pCertContext. /// public uint idxCert; /// TRUE if a countersignature is being viewed. If this is TRUE, idxCounterSigner must be valid. [MarshalAs(UnmanagedType.Bool)] public bool fCounterSigner; /// The index of the countersigner to view. public uint idxCounterSigner; /// /// The number of other stores in the rghStores array of certificate stores to search when building and validating the /// certificate chain. /// public uint cStores; /// /// An array of HCERTSTORE handles to other certificate stores to search when building and validating the certificate chain. /// public IntPtr rghStores; /// The number of property pages to add to the dialog box. public uint cPropSheetPages; /// /// An array of property pages to add to the dialog box. Each page in this array will not receive the lParam in the /// PROPSHEETPAGE structure as the lParam in the WM_INITDIALOG message. It will instead receive a pointer to a /// CRYPTUI_INITDIALOG_STRUCT structure. It contains the lParam in PROPSHEETPAGE and the pointer to the /// CERT_CONTEXT for which the page is being displayed. /// public IntPtr rgPropSheetPages; /// /// The index of the initial page that will be displayed. If the highest bit (0x8000) is set, the index is assumed to index /// rgPropSheetPages (after the highest bit has been stripped off, for example, 0x8000 will indicate the first page in /// rgPropSheetPages). If the highest bit is zero, nStartPage will be the starting index of the default /// certificate dialog box property pages. /// public uint nStartPage; } /// /// /// [The CRYPTUI_WIZ_DIGITAL_SIGN_BLOB_INFO structure is available for use in the operating systems specified in the /// Requirements section. It may be altered or unavailable in subsequent versions.] /// /// /// The CRYPTUI_WIZ_DIGITAL_SIGN_BLOB_INFO structure contains information about the public key BLOB used by the /// CryptUIWizDigitalSign function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_wiz_digital_sign_blob_info typedef struct // _CRYPTUI_WIZ_DIGITAL_SIGN_BLOB_INFO { DWORD dwSize; GUID *pGuidSubject; DWORD cbBlob; BYTE *pbBlob; LPCWSTR pwszDisplayName; } // CRYPTUI_WIZ_DIGITAL_SIGN_BLOB_INFO, *PCRYPTUI_WIZ_DIGITAL_SIGN_BLOB_INFO; [PInvokeData("cryptuiapi.h", MSDNShortId = "9750f52a-f605-4f43-98e1-0f0ea947a214")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_WIZ_DIGITAL_SIGN_BLOB_INFO { /// The size, in bytes, of the structure. public uint dwSize; /// /// A pointer to a GUID that contains the GUID that identifies the Session Initiation Protocol (SIP) functions to load. /// public IntPtr pGuidSubject; /// The size, in bytes, of the BLOB pointed to by the pbBlob member. public uint cbBlob; /// A pointer to the BLOB to sign. public IntPtr pbBlob; /// A pointer to a null-terminated Unicode string that contains the display name of the BLOB to sign. [MarshalAs(UnmanagedType.LPWStr)] public string pwszDisplayName; } /// /// /// [The CRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO structure is available for use in the operating systems specified in the /// Requirements section. It may be altered or unavailable in subsequent versions.] /// /// /// The CRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO structure contains information about the PVK file that contains the /// certificates used by the CryptUIWizDigitalSign function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_wiz_digital_sign_cert_pvk_info typedef struct // _CRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO { DWORD dwSize; LPWSTR pwszSigningCertFileName; DWORD dwPvkChoice; union { // PCCRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE_INFO pPvkFileInfo; PCRYPT_KEY_PROV_INFO pPvkProvInfo; }; } // CRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO, *PCRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO; [PInvokeData("cryptuiapi.h", MSDNShortId = "0316ed0b-d4e5-4102-9ab0-637e96c7d9f5")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO { /// The size, in bytes, of the structure. public uint dwSize; /// /// A pointer to a null-terminated Unicode string that contains the path and file named of the file that contains the signing certificates. /// [MarshalAs(UnmanagedType.LPWStr)] public string pwszSigningCertFileName; /// /// Specifies the type of entity that contains the certificates. This can be one of the following values. /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE /// The entity is a PVK file. /// /// /// CRYPTUI_WIZ_DIGITAL_SIGN_PVK_PROV /// The entity is a PVK provider. /// /// /// public uint dwPvkChoice; /// /// A pointer to a CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE_INFO structure that contains the PVK file that contains the certificates. /// This member is used if CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE is specified for the dwPvkChoice member. /// OR /// /// A pointer to a CRYPT_KEY_PROV_INFO structure that contains information about the PVK provider that contains the /// certificates. This member is used if CRYPTUI_WIZ_DIGITAL_SIGN_PVK_PROV is specified for the dwPvkChoice member. /// /// public IntPtr pPvkInfo; } /// /// /// [The CRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT structure is available for use in the operating systems specified in the /// Requirements section. It may be altered or unavailable in subsequent versions.] /// /// /// The CRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT structure is used with the CryptUIWizDigitalSign function to contain information /// about a BLOB. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_wiz_digital_sign_context typedef struct // _CRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT { DWORD dwSize; DWORD cbBlob; BYTE *pbBlob; } CRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT, *PCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT; [PInvokeData("cryptuiapi.h", MSDNShortId = "3e4eb745-0c28-4ce5-870b-d24565ef0cae")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT { /// The size, in bytes, of the structure. public uint dwSize; /// The size, in bytes, of the BLOB pointed to by the pbBlob member. public uint cbBlob; /// A pointer to the signed BLOB. public IntPtr pbBlob; } /// /// /// [The CRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO structure is available for use in the operating systems specified in the /// Requirements section. It may be altered or unavailable in subsequent versions.] /// /// /// The CRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO structure is used with the CRYPTUI_WIZ_DIGITAL_SIGN_INFO structure to contain /// extended information about a signature. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_wiz_digital_sign_extended_info typedef struct // _CRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO { DWORD dwSize; DWORD dwAttrFlags; LPCWSTR pwszDescription; LPCWSTR pwszMoreInfoLocation; // LPCSTR pszHashAlg; LPCWSTR pwszSigningCertDisplayString; HCERTSTORE hAdditionalCertStore; PCRYPT_ATTRIBUTES psAuthenticated; // PCRYPT_ATTRIBUTES psUnauthenticated; } CRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO, *PCRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO; [PInvokeData("cryptuiapi.h", MSDNShortId = "e061aac4-8c9f-4282-a8f8-bc0c5a10e566")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO { /// The size, in bytes, of the structure. public uint dwSize; /// /// A value that indicates the type of the signature. This can be one of the following values. /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_DIGITAL_SIGN_COMMERCIAL /// The signature is a commercial signature. /// /// /// CRYPTUI_WIZ_DIGITAL_SIGN_INDIVIDUAL /// The signature is a personal signature. /// /// /// public CryptUIWizSigType dwAttrFlags; /// A pointer to a null-terminated Unicode string that contains the description of the subject of the signature. [MarshalAs(UnmanagedType.LPWStr)] public string pwszDescription; /// /// A pointer to a null-terminated Unicode string that contains the location from which to get more information about the file. /// This information will be displayed when the file is downloaded. /// [MarshalAs(UnmanagedType.LPWStr)] public string pwszMoreInfoLocation; /// /// A pointer to a null-terminated ANSI string that contains the object identifier (OID) of the hash algorithm used for the /// signature. The default value is NULL, which indicates that the SHA-1 hash algorithm is used. /// public StrPtrAnsi pszHashAlg; /// /// A pointer to a null-terminated Unicode string that contains the string displayed on the digital signature wizard page. The /// string should prompt the user to select a certificate for a specific purpose. /// [MarshalAs(UnmanagedType.LPWStr)] public string pwszSigningCertDisplayString; /// A handle to an additional certificate store that will be added to the signature. public HCERTSTORE hAdditionalCertStore; /// A pointer to a CRYPT_ATTRIBUTES structure that contains authenticated attributes supplied by the user. public IntPtr psAuthenticated; /// A pointer to a CRYPT_ATTRIBUTES structure that contains unauthenticated attributes supplied by the user. public IntPtr psUnauthenticated; } /// /// /// [The CRYPTUI_WIZ_DIGITAL_SIGN_INFO structure is available for use in the operating systems specified in the Requirements /// section. It may be altered or unavailable in subsequent versions.] /// /// /// The CRYPTUI_WIZ_DIGITAL_SIGN_INFO structure contains information about digital signing. This structure is used by the /// CryptUIWizDigitalSign function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_wiz_digital_sign_info typedef struct // _CRYPTUI_WIZ_DIGITAL_SIGN_INFO { DWORD dwSize; DWORD dwSubjectChoice; union { LPCWSTR pwszFileName; // PCCRYPTUI_WIZ_DIGITAL_SIGN_BLOB_INFO pSignBlobInfo; }; DWORD dwSigningCertChoice; union { PCCERT_CONTEXT pSigningCertContext; // PCCRYPTUI_WIZ_DIGITAL_SIGN_STORE_INFO pSigningCertStore; PCCRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO pSigningCertPvkInfo; }; LPCWSTR // pwszTimestampURL; DWORD dwAdditionalCertChoice; PCCRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO pSignExtInfo; } // CRYPTUI_WIZ_DIGITAL_SIGN_INFO, *PCRYPTUI_WIZ_DIGITAL_SIGN_INFO; [PInvokeData("cryptuiapi.h", MSDNShortId = "22d0bc45-0f66-4f5f-87d3-0849c4327eed")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_WIZ_DIGITAL_SIGN_INFO { /// The size, in bytes, of the structure. public uint dwSize; /// /// /// A value that indicates the entity that is to be signed. This member is required if CRYPTUI_WIZ_NO_UI is specified in /// the dwFlags parameter of the CryptUIWizDigitalSign function. This can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_DIGITAL_SIGN_SUBJECT_BLOB /// The memory BLOB specified by the pSignBlobInfo member is to be signed. /// /// /// CRYPTUI_WIZ_DIGITAL_SIGN_SUBJECT_FILE /// The file specified by the pwszFileName member is to be signed. /// /// /// 0 /// The user will be prompted for a file to sign. /// /// /// public CryptUIWizToSign dwSubjectChoice; /// public CRYPTUI_WIZ_DIGITAL_SIGN_INFO_UNION ToSign; /// [StructLayout(LayoutKind.Explicit)] public struct CRYPTUI_WIZ_DIGITAL_SIGN_INFO_UNION { /// /// A pointer to a null-terminated Unicode string that contains the path and file name of the file to sign. This member is /// used if CRYPTUI_WIZ_DIGITAL_SIGN_SUBJECT_FILE is specified for the dwSubjectChoice member. /// [FieldOffset(0)] public StrPtrUni pwszFileName; /// /// A pointer to a CRYPTUI_WIZ_DIGITAL_SIGN_BLOB_INFO structure that contains the BLOB to sign. This member is used if /// CRYPTUI_WIZ_DIGITAL_SIGN_SUBJECT_BLOB is specified for the dwSubjectChoice member. /// [FieldOffset(0)] public IntPtr pSignBlobInfo; } /// /// /// A value that specifies the location of the certificate that is used to sign the entity. The default value is zero. This can /// be one of the following values. /// /// /// Note If CRYPTUI_WIZ_NO_UI is specified in the dwFlags parameter of the CryptUIWizDigitalSign function, this /// value must be either CRYPTUI_WIZ_DIGITAL_SIGN_CERT or CRYPTUI_WIZ_DIGITAL_SIGN_PVK. /// /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_DIGITAL_SIGN_CERT /// The certificate is contained in the CERT_CONTEXT structure pointed to by the pSigningCertContext member. /// /// /// CRYPTUI_WIZ_DIGITAL_SIGN_STORE /// /// The certificate is contained in the certificate store contained in the CRYPTUI_WIZ_DIGITAL_SIGN_STORE_INFO structure pointed /// to by the pSigningCertStore member. /// /// /// /// CRYPTUI_WIZ_DIGITAL_SIGN_PVK /// /// The certificate is contained in the PVK file contained in the CRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO structure pointed to by /// the pSigningCertPvkInfo member. /// /// /// /// 0 /// The certificates in the My store are used. /// /// /// public CryptUIWizSignLoc dwSigningCertChoice; /// /// A pointer to a CERT_CONTEXT structure that contains the certificate to use to sign the entity. This member is used if /// CRYPTUI_WIZ_DIGITAL_SIGN_CERT is specified for the dwSigningCertChoice member. /// OR /// /// A pointer to a CRYPTUI_WIZ_DIGITAL_SIGN_STORE_INFO structure that contains the certificate to use to sign the entity. This /// member is used if CRYPTUI_WIZ_DIGITAL_SIGN_STORE is specified for the dwSigningCertChoice member. /// /// OR /// /// A pointer to a CRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO structure that contains the certificate to use to sign the entity. /// This member is used if CRYPTUI_WIZ_DIGITAL_SIGN_PVK is specified for the dwSigningCertChoice member. /// /// public IntPtr pSigningCertObject; /// A pointer to a null-terminated Unicode string that contains the URL for the time stamp. [MarshalAs(UnmanagedType.LPWStr)] public string pwszTimestampURL; /// /// /// A value that indicates whether additional certificates will be included in the signature. The default value is zero. This /// can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_DIGITAL_SIGN_ADD_CHAIN /// The entire certificate chain will be included in the signature. /// /// /// CRYPTUI_WIZ_DIGITAL_SIGN_ADD_CHAIN_NO_ROOT /// All certificates in the certificate chain except the root will be included in the signature. /// /// /// 0 /// No additional certificates will be included in the signature. /// /// /// public CryptUIWizAddChoice dwAdditionalCertChoice; /// /// A pointer to a CRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO structure that contains extended information about the signature. /// public IntPtr pSignExtInfo; } /// /// /// [The CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE_INFO structure is available for use in the operating systems specified in the /// Requirements section. It may be altered or unavailable in subsequent versions.] /// /// /// The CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE_INFO structure is used with the CRYPTUI_WIZ_DIGITAL_SIGN_INFO structure to contain /// information about the PVK file used by the digital signature wizard. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_wiz_digital_sign_pvk_file_info typedef struct // _CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE_INFO { DWORD dwSize; LPWSTR pwszPvkFileName; LPWSTR pwszProvName; DWORD dwProvType; } // CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE_INFO, *PCRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE_INFO; [PInvokeData("cryptuiapi.h", MSDNShortId = "0e737661-2cc3-47be-ab32-0efbc18fefbd")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE_INFO { /// The size, in bytes, of the structure. public uint dwSize; /// A pointer to a null-terminated Unicode string that contains the path and file name of the PVK file. [MarshalAs(UnmanagedType.LPWStr)] public string pwszPvkFileName; /// A pointer to a null-terminated Unicode string that contains the name of the provider. [MarshalAs(UnmanagedType.LPWStr)] public string pwszProvName; /// /// Contains the provider type identifier. For more information about the provider types, see Cryptographic Provider Types. /// public uint dwProvType; } /// /// /// [The CRYPTUI_WIZ_DIGITAL_SIGN_STORE_INFO structure is available for use in the operating systems specified in the /// Requirements section. It may be altered or unavailable in subsequent versions.] /// /// /// The CRYPTUI_WIZ_DIGITAL_SIGN_STORE_INFO structure contains information about the certificate store used by the digital /// signature wizard. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_wiz_digital_sign_store_info typedef struct // _CRYPTUI_WIZ_DIGITAL_SIGN_STORE_INFO { DWORD dwSize; DWORD cCertStore; HCERTSTORE *rghCertStore; PFNCFILTERPROC pFilterCallback; // void *pvCallbackData; } CRYPTUI_WIZ_DIGITAL_SIGN_STORE_INFO, *PCRYPTUI_WIZ_DIGITAL_SIGN_STORE_INFO; [PInvokeData("cryptuiapi.h", MSDNShortId = "d3ffbf1c-e8c2-44ab-84d2-d32350d04407")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_WIZ_DIGITAL_SIGN_STORE_INFO { /// The size, in bytes, of the structure. This value must be set to . public uint dwSize; /// Number of certificates in the rghCertStore member. public uint cCertStore; /// A pointer to a handle to the certificate store that will be used by the digital signature wizard. public IntPtr rghCertStore; /// Filter callback function used to display the certificate. [MarshalAs(UnmanagedType.FunctionPtr)] public PFNCFILTERPROC pFilterCallback; /// A pointer to the callback data. public IntPtr pvCallbackData; } /// /// /// [The CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO structure is available for use in the operating systems specified in the /// Requirements section. It may be altered or unavailable in subsequent versions.] /// /// /// The CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO structure contains information that controls the operation of the /// CryptUIWizExport function when a certificate is the object being exported. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_wiz_export_certcontext_info typedef struct // _CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO { DWORD dwSize; DWORD dwExportFormat; BOOL fExportChain; BOOL fExportPrivateKeys; LPCWSTR // pwszPassword; BOOL fStrongEncryption; } CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO, *PCRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO; [PInvokeData("cryptuiapi.h", MSDNShortId = "6be86c4f-0ac7-43c2-81fb-9767279ebeaf")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO { /// The size, in bytes, of this structure. public uint dwSize; /// /// A value that indicates the export format of the certificate. This member can be one of the following values. /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_EXPORT_FORMAT_DER /// Export in Abstract Syntax Notation One (ASN.1) Distinguished Encoding Rules (DER) format. /// /// /// CRYPTUI_WIZ_EXPORT_FORMAT_PFX /// Export in Private Information Exchange (PFX) format. /// /// /// CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7 /// Export in Public Key Cryptography Standard #7 (PKCS #7) format. /// /// /// CRYPTUI_WIZ_EXPORT_FORMAT_BASE64 /// Export in base 64 format. /// /// /// CRYPTUI_WIZ_EXPORT_FORMAT_CRL /// Export in certificate revocation list (CRL) format. /// /// /// CRYPTUI_WIZ_EXPORT_FORMAT_CTL /// Export in certificate trust list (CTL) format. /// /// /// public uint dwExportFormat; /// /// Indicates whether the certificate chain should be exported in addition to the certificate. Contains nonzero to export the /// chain or zero to not export the chain. /// [MarshalAs(UnmanagedType.Bool)] public bool fExportChain; /// /// Indicates whether the private key should be exported in addition to the certificate. Contains nonzero to export the private /// key or zero to not export the private key. /// [MarshalAs(UnmanagedType.Bool)] public bool fExportPrivateKeys; /// /// A pointer to a null-terminated Unicode string that contains the password used to access the private key. This is required if /// fExportPrivateKeys is nonzero and is otherwise ignored. /// [MarshalAs(UnmanagedType.LPWStr)] public string pwszPassword; /// /// /// Indicates whether strong encryption should be used in the export process. Contains nonzero to use strong encryption or zero /// to use weak encryption. This must be nonzero if dwExportFormat is CRYPTUI_WIZ_EXPORT_FORMAT_PFX. If this is /// nonzero, the PFX BLOB produced is not compatible with Internet Explorer 4.0 or earlier versions. /// /// /// Note We recommend that you set this to nonzero; otherwise, a substantially weaker encryption algorithm is used in the /// export process. /// /// [MarshalAs(UnmanagedType.Bool)] public bool fStrongEncryption; } /// /// /// [The CRYPTUI_WIZ_EXPORT_INFO structure is available for use in the operating systems specified in the Requirements /// section. It may be altered or unavailable in subsequent versions.] /// /// /// The CRYPTUI_WIZ_EXPORT_INFO structure contains information that controls the operation of the CryptUIWizExport function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_wiz_export_info typedef struct // _CRYPTUI_WIZ_EXPORT_INFO { DWORD dwSize; LPCWSTR pwszExportFileName; DWORD dwSubjectChoice; union { PCCERT_CONTEXT pCertContext; // PCCTL_CONTEXT pCTLContext; PCCRL_CONTEXT pCRLContext; HCERTSTORE hCertStore; }; DWORD cStores; HCERTSTORE *rghStores; } // CRYPTUI_WIZ_EXPORT_INFO, *PCRYPTUI_WIZ_EXPORT_INFO; [PInvokeData("cryptuiapi.h", MSDNShortId = "3c509bb6-d391-4b59-809c-23466c8196ea")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_WIZ_EXPORT_INFO { /// The size, in bytes, of this structure. public uint dwSize; /// /// A pointer to a null-terminated Unicode string that contains the fully qualified file name to export to. If this member is /// not NULL and the CRYPTUI_WIZ_NO_UI flag in the dwFlags parameter of the CryptUIWizExport function is not set, /// this string is displayed to the user as the default file name. This member is required if the CRYPTUI_WIZ_NO_UI flag /// is set. This member is otherwise optional. /// [MarshalAs(UnmanagedType.LPWStr)] public string pwszExportFileName; /// /// Indicates the type of the subject to export. This member can be one of the following values. /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_EXPORT_CERT_CONTEXT /// Export the certificate context that is specified in the pCertContext member. /// /// /// CRYPTUI_WIZ_EXPORT_CTL_CONTEXT /// Export the certificate trust list (CTL) context that is specified in the pCTLContext member. /// /// /// CRYPTUI_WIZ_EXPORT_CRL_CONTEXT /// Export the certificate revocation list (CRL) context that is specified in the pCRLContext member. /// /// /// CRYPTUI_WIZ_EXPORT_CERT_STORE /// Export the certificate store that is specified in the hCertStore member. /// /// /// CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY /// Export only the certificates from the certificate store that is specified in the hCertStore member. /// /// /// public CryptUIWizExportType dwSubjectChoice; /// public CRYPTUI_WIZ_EXPORT_INFO_UNION Subject; /// [StructLayout(LayoutKind.Explicit)] public struct CRYPTUI_WIZ_EXPORT_INFO_UNION { /// /// A pointer to the CERT_CONTEXT structure that contains the certificate to export. This member is used if the /// dwSubjectChoice member contains CRYPTUI_WIZ_EXPORT_CERT_CONTEXT. /// [FieldOffset(0)] public PCCERT_CONTEXT pCertContext; /// /// A pointer to the CTL_CONTEXT structure that contains the CTL to export. This member is used if the /// dwSubjectChoice member contains CRYPTUI_WIZ_EXPORT_CTL_CONTEXT. /// [FieldOffset(0)] public PCCTL_CONTEXT pCTLContext; /// /// A pointer to the CRL_CONTEXT structure that contains the CRL to export. This member is used if the /// dwSubjectChoice member contains CRYPTUI_WIZ_EXPORT_CRL_CONTEXT. /// [FieldOffset(0)] public PCCRL_CONTEXT pCRLContext; /// /// A handle to the certificate store to export. This member is used if the dwSubjectChoice member contains /// CRYPTUI_WIZ_EXPORT_CERT_STORE or CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY. /// [FieldOffset(0)] public HCERTSTORE hCertStore; } /// The number of elements in the rghStores array. public uint cStores; /// /// An array of extra certificate stores to search for certificates in the trust chain if the chain is being exported with a /// certificate. This member is ignored if dwSubjectChoice is anything other than the /// CRYPTUI_WIZ_EXPORT_CERT_CONTEXT value. The cStores member contains the number of elements in this array. /// public IntPtr rghStores; } /// /// /// [The CRYPTUI_WIZ_IMPORT_SRC_INFO structure is available for use in the operating systems specified in the Requirements /// section. It may be altered or unavailable in subsequent versions.] /// /// /// The CRYPTUI_WIZ_IMPORT_SRC_INFO structure contains the subject to import into the CryptUIWizImport function. The subject /// can be a certificate, a certificate trust list (CTL), or a certificate revocation list (CRL). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/cryptuiapi/ns-cryptuiapi-cryptui_wiz_import_src_info typedef struct // _CRYPTUI_WIZ_IMPORT_SUBJECT_INFO { DWORD dwSize; DWORD dwSubjectChoice; union { LPCWSTR pwszFileName; PCCERT_CONTEXT // pCertContext; PCCTL_CONTEXT pCTLContext; PCCRL_CONTEXT pCRLContext; HCERTSTORE hCertStore; }; DWORD dwFlags; LPCWSTR // pwszPassword; } CRYPTUI_WIZ_IMPORT_SRC_INFO, *PCRYPTUI_WIZ_IMPORT_SRC_INFO; [PInvokeData("cryptuiapi.h", MSDNShortId = "17d932e3-05ea-4ed0-9f88-fbb674b6b070")] [StructLayout(LayoutKind.Sequential)] public struct CRYPTUI_WIZ_IMPORT_SRC_INFO { /// The size, in bytes, of this structure. public uint dwSize; /// /// Indicates the type of subject to import. This member can be one of the following values. /// /// /// Value /// Meaning /// /// /// CRYPTUI_WIZ_IMPORT_SUBJECT_FILE /// Import the certificate stored in the file referenced in the pwszFileName member. /// /// /// CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_CONTEXT /// Import the certificate referenced in the pCertContext member. /// /// /// CRYPTUI_WIZ_IMPORT_SUBJECT_CTL_CONTEXT /// Import the CTL referenced in the pCTLContext member. /// /// /// CRYPTUI_WIZ_IMPORT_SUBJECT_CRL_CONTEXT /// Import the CRL referenced in the pCRLContext member. /// /// /// CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_STORE /// Import the certificate store referenced in the hCertStore member. /// /// /// public CryptUIWizImportType dwSubjectChoice; /// public CRYPTUI_WIZ_IMPORT_SRC_INFO_UNION Subject; /// [StructLayout(LayoutKind.Explicit)] public struct CRYPTUI_WIZ_IMPORT_SRC_INFO_UNION { /// /// A pointer to a null-terminated Unicode string that contains the path and file name of the file that contains the /// certificate to import. This member is used if the dwSubjectChoice member contains CRYPTUI_WIZ_IMPORT_SUBJECT_FILE. /// [FieldOffset(0)] public StrPtrUni pwszFileName; /// /// A pointer to the CERT_CONTEXT structure that contains the certificate to import. This member is used if the /// dwSubjectChoice member contains CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_CONTEXT. /// [FieldOffset(0)] public PCCERT_CONTEXT pCertContext; /// /// A pointer to the CTL_CONTEXT structure that contains the CTL to import. This member is used if the /// dwSubjectChoice member contains CRYPTUI_WIZ_IMPORT_SUBJECT_CTL_CONTEXT. /// [FieldOffset(0)] public PCCTL_CONTEXT pCTLContext; /// /// A pointer to the CRL_CONTEXT structure that contains the CRL to import. This member is used if the /// dwSubjectChoice member contains CRYPTUI_WIZ_IMPORT_SUBJECT_CRL_CONTEXT. /// [FieldOffset(0)] public PCCRL_CONTEXT pCRLContext; /// /// A handle to the certificate store to import. This member is used if the dwSubjectChoice member contains CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_STORE. /// [FieldOffset(0)] public HCERTSTORE hCertStore; } /// /// /// Contains flags that modify the import operation. This member is required if pwszFileName contains a Personal /// Information Exchange (PFX) BLOB. Otherwise, this member is ignored. This member can be zero or a combination of one or more /// of the following values. /// /// /// /// Value /// Meaning /// /// /// CRYPT_EXPORTABLE /// /// Imported keys are marked as exportable. If this flag is not used, calls to the CryptExportKey function with the key handle fail. /// /// /// /// CRYPT_USER_PROTECTED /// /// The user is to be notified by means of a dialog box or some other manner when certain actions are attempting to use this /// key. The precise behavior is specified by the cryptographic service provider (CSP) that is being used. Prior to Internet /// Explorer 4.0, Microsoft CSPs ignored this flag. Starting with Internet Explorer 4.0, Microsoft CSPs support this flag. If /// the provider context was opened with the CRYPT_SILENT flag set, using this flag causes a failure, and the last error is set /// to NTE_SILENT_CONTEXT. /// /// /// /// CRYPT_MACHINE_KEYSET /// The private keys are stored under the local computer and not under the current user. /// /// /// CRYPT_USER_KEYSET /// /// The private keys are stored under the current user and not under the local computer, even if the PFX BLOB specifies that /// they should go under the local computer. /// /// /// /// public PFXImportFlags dwFlags; /// /// Pointer to a null-terminated Unicode string that contains the password used to access the private key. A password is /// required if pwszFileName contains a PFX BLOB. If a password is not required, the variable can be an empty string. /// This member cannot be NULL. /// [MarshalAs(UnmanagedType.LPWStr)] public string pwszPassword; } /// Provides a pointer to a CRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT structure. [StructLayout(LayoutKind.Sequential)] public struct PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT(IntPtr preexistingHandle) => handle = preexistingHandle; /// /// Returns an invalid handle by instantiating a object with . /// public static PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT h) => h.handle; /// Performs an explicit conversion from to . /// The handle. /// The resulting instance from the conversion. public static explicit operator CRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT(PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT h) => h.handle.ToStructure(); /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT h1, PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT h1, PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// /// Provides a for that is disposed using . /// public class SafePCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT : SafeHANDLE { /// /// Initializes a new instance of the class and assigns an existing handle. /// /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafePCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafePCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT(SafePCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT h) => h.handle; /// protected override bool InternalReleaseHandle() => CryptUIWizFreeDigitalSignContext(handle); } } }