CryptoSys PKI Toolkit Manual

CMS_QuerySigData

CMS_QuerySigData queries a CMS signed-data object file for selected information.

VB6/VBA Syntax

Public Declare Function CMS_QuerySigData Lib "diCrPKI.dll" (ByVal strDataOut As String, ByVal nDataLen As Long, ByVal strFileIn As String, ByVal strQuery As String, ByVal nOptions As Long) As Long

nRet = CMS_QuerySigData(strDataOut, nDataLen, strFileIn, strQuery, nOptions) As Long

Parameters

strDataOut
[out] String to receive the output.
nDataLen
[in] Long specifying the length of the output string.
strFileIn
[in] String with name of signed-data CMS object file.
strQuery
[in] String specifying the query (see Remarks below).
nOptions
[in] Long option flags:
PKI_DEFAULT (0) for default options
PKI_CMS_FORMAT_BASE64 to read input formatted with base64 encoding (default expected BER-encoded binary)
PKI_QUERY_GETTYPE to return the type of data returned for a given query.

C/C++ Syntax

long _stdcall CMS_QuerySigData(char *szDataOut, long nDataOutLen, const char *szFileIn, const char *szQuery, long nOptions);

Returns (VB6/C)

Long: If successful, the return value is a positive integer indicating either the result itself (if the result is a number) or the number of characters in the output string (if the query is looking for a string). If the item queried cannot be found, the return value is zero. If there is an error (e.g. an invalid signed-data file), it returns a negative error code.

.NET Equivalent

Cms.QuerySigData Method

Remarks

This function queries a given SignedData file for selected information. If the result data type is a number then it returns the value directly. If the result is a string, then it sets strDataOut and returns the number of characters in the string. Note the difference in behaviour depending on the data type of the result for the VB/C functions. However, the C#/VB.NET methods always return a string. The query string is case-insensitive, so "version", "Version" and "VeRsIoN" are all valid. Only version 1 signed-data objects are fully supported. The function will attempt to query other versions but may not succeed. Note that this function does not verify any data, including the messageDigest attribute, it just returns what it finds.

Valid queries are:

Query StringSearches forData Type
versionsignedData version (sdVer) valueNumber
eContentTypeContentType of the EncapsulatedContentInfo, e.g. "data"String
HASeContent1 if eContent is present; 0 if notNumber
CountOfCertificatesNumber of certificates included in the dataNumber
CountOfSignerInfosNumber of SignerInfos included in the dataNumber
signerInfoVersionsignerInfo version (siVer) valueNumber
digestAlgorithmdigestAlgorithm, e.g. "sha1"String
signatureAlgorithmsignatureAlgorithm, e.g. "rsaEncryption"String
HASsignedAttributes1 if signedAttributes (authenticatedAttributes) are present; 0 if notNumber
signingTimesigningTime attribute in format "2005-12-31 23:30:59"String
messageDigestmessageDigest attribute in hexadecimal format, if presentString

By default, the function queries the first signerInfo in the file. To query the nth signerInfo append "/n" to the query string, e.g. "signerInfoVersion/2" to find the version number of the second signerInfo in the file.

To find out the type of data returned for a given query, use the PKI_QUERY_GETTYPE option. The function will return either PKI_QUERY_NUMBER (1) or PKI_QUERY_STRING (2), or a negative "invalid query" error. For example

nRet = CMS_QuerySigData("", 0, "", "version", PKI_QUERY_GETTYPE)

Example

This example queries information from various sample files.

Dim strCMSFile As String
Dim nRet As Long
Dim strOutput As String

' Pre-dimension output string
strOutput = String(64, " ")

strCMSFile = "C:\Test\4.6.bin"
nRet = CMS_QuerySigData(strOutput, Len(strOutput), strCMSFile, "version", 0)
Debug.Print "Version=" & nRet

strCMSFile = "C:\Test\4.7.bin"
nRet = CMS_QuerySigData(strOutput, Len(strOutput), strCMSFile, "version", 0)
Debug.Print "Version=" & nRet
nRet = CMS_QuerySigData(strOutput, Len(strOutput), strCMSFile, "signingTime", 0)
If nRet > 0 Then
    Debug.Print "signingTime=" & Left$(strOutput, nRet)
Else
    Debug.Print "ERROR=" & nRet
End If

strCMSFile = "C:\Test\BasicSignByAlice_attr.bin"
nRet = CMS_QuerySigData(strOutput, Len(strOutput), strCMSFile, "signingTime", 0)
If nRet > 0 Then
    Debug.Print "signingTime=" & Left$(strOutput, nRet)
Else
    Debug.Print "ERROR=" & nRet
End If

In this example, file 4.6.bin is CMS Version 1, file 4.7.bin is CMS Version 3 with no signingTime attribute (if not present, it returns error code zero), and the file BasicSignByAlice_attr.bin was signed at 7:31 a.m. on 25th February 2006:

Version=1
Version=3
ERROR=0
signingTime=2006-02-25 07:31:01

See Also

CMS_ReadSigData CMS_GetSigDataDigest

[Contents] [Index]

[HOME]   [NEXT: CMS_ReadEnvData...]

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