CMS_MakeDetachedSig creates a "detached signature" CMS signed-data object from a message
digest of the content.
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
String with name of output file to be created.String containing the digest of the content in hexadecimal format.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(;)String containing the private key data for the signer.Long option flags:
long _stdcall CMS_MakeDetachedSig(const char *szFileOut, const char *szHexDigest,
const char *szCertList, const char *szRSAPrivateKey, long nOptions);
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.
See CMS_MakeSigData.
The PKI_CMS_EXCLUDE_DATA option is obviously ignored.
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
CMS_MakeSigData CMS_MakeSigDataFromString