CryptAcquireContext (转)

1.

据MSDN说如果CryptAcquireContext的dwFlags包括CRYPT_SILENT,则不能弹出PIN的输入

BOOLEAN CRYPTFUNC CryptAcquireContext(
   HCRYPTPROV* phProv,
   LPCTSTR pszContainer,
   LPCTSTR pszProvider,
   DWORD dwProvType,
   DWORD dwFlags
);

https://msdn.microsoft.com/zh-cn/aa924589

cryptographic service provider (CSP)密码编译服务提供者.

phProv

[out] Pointer to a handle to a CSP.

pszContainer

[in] Pointer to a null-terminated string that identifies the key container to the CSP. This name is independent of the method used to store the keys. Some CSPs store their key containers internally in the hardware, some use the system registry, and others use the file system.

When dwFlags is set to CRYPT_VERIFYCONTEXT,pszContainer must be set to NULL. If this parameter is NULL, a default key container name is used.

Application developers should be carefull when using the default key container. When multiple applications use the same container, one application can change or destroy the keys that another application needs.

An application can obtain the name of the acquired key containerat a later time by reading the PP_CONTAINER CSP parameter with the CryptGetProvParam function.

pszProvider

[in] Pointer to a null-terminated string that specifies the name of the CSP to be used.

If this parameter is NULL, the user default provider is used. For more information about connecting to CSPs, see the programmer's guide topics underCryptography.

An application can obtain the name of the acquired CSP at a later time by reading the PP_NAME CSP parameter with theCryptGetProvParam function.

dwProvType

[in] Specifies the type of provider to acquire. The following provider types are predefined:

  • PROV_RSA_FULL
  • PROV_RSA_SIG
  • PROV_DSS
  • PROV_DSS_DH
  • PROV_FORTEZZA
  • PROV_MS_EXCHANGE
  • PROV_SSL
  • PROV_EC_ECDSA_SIG
  • PROV_EC_ECNRA_SIG
  • PROV_EC_ECDSA_FULL
  • PROV_EC_ECNRA_FULL
  • PROV_SPYRUS_LYNKS
  • PROV_RNG
  • PROV_INTEL_SEC
dwFlags

[in] Bitmask of flags. This parameter is usually set to zero. The following table shows flags that can be set.

FlagDescription

CRYPT_VERIFYCONTEXT

If this flag is set, the application has no access to the private keys and thepszContainer parameter must be set to NULL.

This option is intended for applications that do not use private keys.

When CryptAcquireContext is called, many CSPs require input from the owning user before granting access to the private keys in the key container. For example, the private keys may be encrypted, requiring a password from the user before they can be used. However, if the CRYPT_VERIFYCONTEXT flag is specified, access to the private keys is not required and the user interface can be bypassed.

CRYPT_NEWKEYSET

If this flag is set, a new key container is created with the name specified bypszContainer. If pszContainer is NULL, a key container with the default name is created. See CRYPT_MACHINE_KEYSET for information on combining flags.

CRYPT_MACHINE_KEYSET

By default, key containers are stored in the HKEY_CURRENT_USER registry hive. The CRYPT_MACHINE_KEYSET flag can be set and combined with all of the other flags to indicate that the key container is stored in the HKEY_LOCAL_MACHINE hive instead.

CRYPT_DELETEKEYSET

If this flag is set, then the key container specified by pszContainer is deleted. IfpszContainer is NULL, then the key container with the default name is deleted. All key pairs in the key container are also destroyed.

When the CRYPT_DELETEKEYSET flag is set, the value returned in phProv is undefined; therefore, a call to theCryptReleaseContext function is not required.

CRYPT_SILENT

The application requests that the CSP not display any user interface (UI) for this context. If the CSP must display the UI to operate, the call fails with the NTE_SILENT_CONTEXT error. In addition, if a call is made toCryptGenKey with the CRYPT_USER_PROTECTED flag and a context acquired with the CRYPT_SILENT flag, the call fails and the CSP sets NTE_SILENT_CONTEXT.

CRYPT_SILENT is intended for CSP applications that cannot display a UI.

 

 

 

BOOL
WINAPI
CryptAcquireContextA(
    HCRYPTPROV *phProv,
    LPCSTR szContainer,
    LPCSTR szProvider,
    DWORD dwProvType,
    DWORD dwFlags
    );
WINADVAPI
BOOL
WINAPI
CryptAcquireContextW(
    HCRYPTPROV *phProv,
    LPCWSTR szContainer,
    LPCWSTR szProvider,
    DWORD dwProvType,
    DWORD dwFlags
    );


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值