CryptSignAndEncodeCertificate
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(
HCRYPTPROV hCryptProv,
DWORD dwKeySpec,
DWORD dwCertEncodingType,
LPCSTR lpszStructType,
const void* pvStructInfo,
PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
const void* pvHashAuxInfo,
PBYTE pbEncoded,
DWORD* pcbEncoded
);
Parameters
hCryptProv
[in] Handle to the CSP to do the signature. This handle must have already been created using the CryptAcquireContext function.dwKeySpec
[in] Specifies the private key to use from the provider's container. The value can be AT_KEYEXCHANGE or AT_SIGNATURE.dwCertEncodingType
[in] Specifies the encoding type used. Currently, only X509_ASN_ENCODING is used; however, additional encoding types may be added in the future.lpszStructType
[in] Long pointer to one of the following predefined string constants used with encode operations:X509_CERT_CRL_TO_BE_SIGNED
X509_CERT_REQUEST_TO_BE_SIGNED
X509_CERT_TO_BE_SIGNED
X509_KEYGEN_REQUEST_TO_BE_SIGNED
pvStructInfo
[in] Pointer to the structure to be signed and encoded. The following structures are the most commonly used structures:pSignatureAlgorithm
[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:szOID_RSA_MD5RSA
szOID_RSA_SHA1RSA
szOID_X957_SHA1DSA
pvHashAuxInfo
[in] Reserved. Must be NULL.pbEncoded
[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.
pcbEncoded
[in, out] On input, pointer to a DWORD that contains the size, in bytes, of the buffer pointed to by the pbEncoded parameter. On output, the DWORD contains the number of bytes stored or to be stored in the buffer.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, or TRUE.
If the function fails, the return value is zero, or FALSE.
For extended error information, call the GetLastError function.
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. |
Remarks
The desktop platform supports the flag PKCS_7_ASN_ENCODING, but Windows CE does not and ignores the flag when it is specified.
Requirements
OS Versions: Windows CE 3.0 and later.
Header: Wincrypt.h.
Link Library: Crypt32.lib.
See Also
CryptAcquireContext | CryptCreateHash | CryptHashData | CryptSignCertificate | CryptSignHash | CERT_INFO | CERT_REQUEST_INFO | CERT_KEYGEN_REQUEST_INFO | CRYPT_ALGORITHM_IDENTIFIER
Last updated on Thursday, April 08, 2004
© 1992-2003 Microsoft Corporation. All rights reserved.