Partager via


CryptSignCertificate (Compact 2013)

3/28/2014

This function signs the to-be-signed information in the encoded signed content.

Syntax

BOOL WINAPI CryptSignCertificate(
  HCRYPTPROV hCryptProv,
  DWORD dwKeySpec,
  DWORD dwCertEncodingType,
  const BYTE* pbEncodedToBeSigned,
  DWORD cbEncodedToBeSigned,
  PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  const void* pvHashAuxInfo,
  BYTE* pbSignature,
  DWORD* pcbSignature
);

Parameters

  • hCryptProv
    [in] Handle to the CSP that does the signature. This handle must have already been created using the CryptAcquireContext function.
  • dwKeySpec
    [in] Specifies the private key to be used from the provider's container. The value can be AT_KEYEXCHANGE or AT_SIGNATURE.
  • dwCertEncodingType
    [in] Specifies the encoding type used. Only X509_ASN_ENCODING is used.
  • pbEncodedToBeSigned
    [in] Pointer to the encoded content to be signed.
  • cbEncodedToBeSigned
    [in] Size, in bytes, of the encoded content, pbEncodedToBeSigned.
  • pSignatureAlgorithm
    [in] Pointer to a CRYPT_ALGORITHM_IDENTIFIER structure with a pszObjId member set to one of the following values:

    szOID_RSA_MD5RSA

    szOID_RSA_SHA1RSA

    szOID_X957_SHA1DSA

  • pvHashAuxInfo
    [in] Not currently used. Must be NULL.
  • pbSignature
    [out] Pointer to a buffer to receive the signed hash of the content. This parameter can be NULL to set the size of this information for memory allocation purposes.
  • pcbSignature
    [in, out] On input, pointer to a DWORD that contains the size, in bytes, of the buffer pointed to by the pbSignature 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 Value

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 pbSignature 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 pcbSignature parameter.

NTE_BAD_ALGID

The signature algorithm's object identifier does not map to a known or supported hash algorithm.

Remarks

The desktop operating system supports the flag PKCS_7_ASN_ENCODING, but Windows Embedded Compact does not and ignores the flag when it is specified.

Requirements

Header

wincrypt.h

Library

crypt32.lib

See Also

Reference

Certificates Functions
CryptAcquireContext
CryptCreateHash
CryptHashData
CryptSignAndEncodeCertificate
CryptSignHash
CRYPT_ALGORITHM_IDENTIFIER