CryptoSys PKI Toolkit Manual

CMS_MakeDetachedSig

CMS_MakeDetachedSig creates a "detached signature" CMS signed-data object from a message digest of the content.

VB6/VBA Syntax

Public Declare Function CMS_MakeDetachedSig Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strHexDigest As String, ByVal strCertList As String, ByVal strPrivateKey As String, ByVal nOptions As Long) As Long

nRet = CMS_MakeDetachedSig(strFileOut, strHexDigest, strCertList, strPrivateKey, nOptions) As Long

Parameters

strFileOut
[in] String with name of output file to be created.
strHexDigest
[in] String containing the digest of the content in hexadecimal format.
strCertList
[in] String containing the filename of the signer's certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons(;)
strPrivateKey
[in] String containing the private key data for the signer.
nOptions
[in] Long option flags:
PKI_DEFAULT (0) for default options
PKI_CMS_EXCLUDE_CERTS to exclude signer's certificate
PKI_CMS_INCLUDE_ATTRS to include the two signed attributes content-type and message-digest
PKI_CMS_ADD_SIGNTIME to add SigningTime to the signed attributes
PKI_CMS_ADD_SMIMECAP to add sMIMECapabilities to the signed attributes
PKI_CMS_FORMAT_BASE64 to format the output with base64 encoding (default output is binary)

C/C++ Syntax

long _stdcall CMS_MakeDetachedSig(const char *szFileOut, const char *szHexDigest, const char *szCertList, const char *szRSAPrivateKey, long nOptions);

Returns (VB6/C)

Long: If successful, the return value is zero; otherwise it returns a non-zero error code. Further error information may be available by calling PKI_LastError.

.NET Equivalent

Cms.MakeDetachedSig Method

Remarks

See CMS_MakeSigData. The PKI_CMS_EXCLUDE_DATA option is obviously ignored.

Example

This example creates a "detached signature" CMS signed-data object that would duplicate a "detached signature" version of example 4.2 from [SMIME-EX] if they did one. It uses Alice's RSA private key to sign the SHA-1 Message digest of the content "This is some sample content.". The output is a BER-encoded CMS signedData object which includes her certificate but has no signed attributes.

Dim nRet As Long
Dim strEPKFile As String
Dim strCertFile As String
Dim strOutFile As String
Dim strHexDigest As String
Dim strPrivateKey As String

strEPKFile = "C:\Test\AlicePrivRSASign.epk"
strCertFile = "C:\Test\AliceRSASignByCarl.cer"
strOutFile = "C:\Test\DetSignByAlice.bin"
strHexDigest = "406aec085279ba6e16022d9e0629c0229687dd48"

' First, Alice reads her private key into a string
strPrivateKey = rsaReadPrivateKey(strEPKFile, "password")
If Len(strPrivateKey) = 0 Then
    MsgBox "Cannot read private key"
    Exit Function
End If

' Alice makes a detached signature using
' the hash of the content and her private key
nRet = CMS_MakeDetachedSig(strOutFile, strHexDigest, _
    strCertFile, strPrivateKey, 0)
Debug.Print "CMS_MakeDetachedSig returns " & nRet

See Also

CMS_MakeSigData CMS_MakeSigDataFromString

[Contents] [Index]

[HOME]   [NEXT: CMS_MakeEnvData...]

Copyright © 2004-9 D.I. Management Services Pty Ltd. All rights reserved.