Windows CE 3.0

This function encodes and signs a certificate or certificate request. This function performs the following operations:

  • Calls the CryptEncodeObject function using the lpszStructType parameter to encode the "to be signed" information.
  • Calls the CryptSignCertificate function to sign this encoded information.
  • Calls the CryptEncodeObject function again, with the lpszStructType parameter set to X509_CERT, to further encode the resulting signed, encoded information.
BOOL WINAPI CryptSignAndEncodeCertificate(
DWORD dwKeySpec,
DWORD dwCertEncodingType,
LPCSTR lpszStructType,
const void *pvStructInfo,
const void *pvHashAuxInfo,
PBYTE pbEncoded,
DWORD *pcbEncoded


[in] Handle of the CSP to do the signature. This handle must have already been created using the CryptAcquireContext function.
[in] Identifies the private key to use from the provider's container. It can be AT_KEYEXCHANGE or AT_SIGNATURE.
[in] Specifies the encoding type used. Currently, only X509_ASN_ENCODING is used; however, additional encoding types may be added in the future.
[in] The following predefined lpszStructType constants are used with encode operations:





[in] Pointer to the structure to be signed and encoded. The most commonly used structures are:




[in] Pointer to a CRYPT_ALGORITHM_IDENTIFIER structure containing the OID of the signature algorithm and any additional parameters needed. The CryptSignAndEncodeCertificate function uses the following algorithm OIDs:




[in] Reserved. Must be NULL.
[out] Pointer to a buffer to receive the signed and encoded output.

This parameter can be NULL to set the size of this information for memory allocation purposes.

[in/out] Pointer to a DWORD that contains the size, in bytes, of the buffer pointed to by the pbEncoded parameter. When the function returns, the DWORD contains the number of bytes stored or to be stored in the buffer.
Note   When processing the data returned in the buffer, applications need to use the actual size of the data returned. The actual size can be slightly smaller than the size of the buffer specified on input. (On input, buffer sizes are usually specified large enough to ensure that the largest possible output data will fit in the buffer.) On output, the variable pointed to by this parameter is updated to reflect the actual size of the data copied to the buffer.

Return Values

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.

Note   Errors from the called CryptCreateHash, CryptSignHash, and CryptHashData functions might be propagated to this function.

The following table shows the error codes for this function.

Error code Description
ERROR_MORE_DATA If the buffer specified by the pbEncoded parameter is not large enough to hold the returned data, the function sets the ERROR_MORE_DATA code and stores the required buffer size, in bytes, into the variable pointed to by the pcbEncoded parameter.
ERROR_FILE_NOT_FOUND Invalid certificate encoding type. Currently only X509_ASN_ENCODING is supported.
NTE_BAD_ALGID The signature algorithm's object Identifier (OID) does not map to a known or supported hash algorithm.
CRYPT_E_BAD_ENCODE An error was encountered while encoding or decoding. The most likely cause of this error is the improper initialization all of the fields in the structure pointed to by the pvStructInfo parameter.


The desktop platform supports the PKCS_7_ASN_ENCODING flag, but Windows CE does not. Windows CE ignores the flag when it is specified.


Runs on Versions Defined in Include Link to
Windows CE OS 3.0 or later Wincrypt.h   Crypt32.lib
Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

CryptAcquireContext, CryptCreateHash, CryptHashData, CryptSignCertificate, CryptSignHash, CERT_INFO, CERT_REQUEST_INFO, CERT_KEYGEN_REQUEST_INFO, CRYPT_ALGORITHM_IDENTIFIER

 Last updated on Tuesday, July 13, 2004

© 1992-2000 Microsoft Corporation. All rights reserved.