CMS_QuerySigData queries a CMS signed-data object file for selected information.
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
String to receive the output.Long specifying the length of the output string.String with name of signed-data CMS object file.String specifying the query (see Remarks below).Long option flags:
long _stdcall CMS_QuerySigData(char *szDataOut, long nDataOutLen, const char *szFileIn,
const char *szQuery, long nOptions);
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.
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 String | Searches for | Data Type |
|---|---|---|
version | signedData version (sdVer) value | Number |
eContentType | ContentType of the EncapsulatedContentInfo, e.g. "data" | String |
HASeContent | 1 if eContent is present; 0 if not | Number |
CountOfCertificates | Number of certificates included in the data | Number |
CountOfSignerInfos | Number of SignerInfos included in the data | Number |
signerInfoVersion | signerInfo version (siVer) value | Number |
digestAlgorithm | digestAlgorithm, e.g. "sha1" | String |
signatureAlgorithm | signatureAlgorithm, e.g. "rsaEncryption" | String |
HASsignedAttributes | 1 if signedAttributes (authenticatedAttributes) are present; 0 if not | Number |
signingTime | signingTime attribute in format "2005-12-31 23:30:59" | String |
messageDigest | messageDigest attribute in hexadecimal format, if present | String |
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)
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
CMS_ReadSigData CMS_GetSigDataDigest