函数原型:
BOOL WINAPI CryptGenKey(
  HCRYPTPROV hProv, 
  ALG_ID Algid, 
  DWORD dwFlags, 
  HCRYPTKEY *phKey 
);参数:
dwFlags 
[in] Specifies the type of key generated. The sizes of a session key, RSA signature key, and RSA key exchange keys can be set when the key is generated. The key size, representing the length of the key modulus in bits, is set with the upper 16 bits of this parameter. Thus, if a 2,048-bit RSA signature key is to be generated, the value 0x08000000 is combined with any other dwFlags predefined value with a bitwise-OR operation. The upper 16 bits of 0x08000000 is 0x0800, or decimal 2048. 
Due to changing export control restrictions, the default CSP and default key length may change between operating system releases. It is important that both the encryption and decryption use the same CSP and that the key length be explicitly set using the dwFlags parameter to ensure interoperability on different operating system platforms. In particular, beginning with Windows XP, the default RSA Full Cryptographic Service Provider is the Microsoft RSA Strong Cryptographic Provider. The default DSS Signature Diffie Hellman Cryptographic Service Provider is the Microsoft Enhanced DSS Diffie Hellman Cryptographic Provider. Each of these CSPs has a default 128-bit symmetric key length for RC2 and RC4 and a 1,024-bit default key length for public key algorithms. Applications that must maintain compatibility with previous versions of Windows must not use default key lengths but must explicitly set the appropriate lengths. If the upper 16 bits is zero, the default key size is generated. If a key larger than the maximum or smaller than the minimum is specified, the call fails with the ERROR_INVALID_PARAMETER code. The following table lists minimum, default, and maximum signature and exchange key lengths through Windows 2000. 

解决方案 »

  1.   

    BOOL WINAPI CryptAcquireContext(
      HCRYPTPROV *phProv,
      LPCTSTR pszContainer,
      LPCTSTR pszProvider,
      DWORD dwProvType,
      DWORD dwFlags
    );参数:
    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 and the NTE_SILENT_CONTEXT error code is set as the last error. In addition, if calls are made to CryptGenKey with the CRYPT_USER_PROTECTED flag with a context that has been acquired with the CRYPT_SILENT flag, the calls fail and the CSP sets NTE_SILENT_CONTEXT. 
    CRYPT_SILENT is intended for use with applications for which the UI cannot be displayed by the CSP. This flag is supported with Microsoft® Windows® 2000 or later. It is not supported in Windows 95, Windows 98, Windows Millennium or Microsoft® Internet Explorer version 5.0.