Reads the content from a CMS signed-data object file directly into a string.
Public Declare Function CMS_ReadSigDataToString Lib "diCrPKI.dll"
(ByVal strDataOut As String, ByVal nDataLen As Long,
ByVal strFileIn As String, ByVal nOptions As Long) As Long
nRet = CMS_ReadSigDataToString(strDataOut, nDataLen, strFileIn,
nOptions) As Long
long __stdcall CMS_ReadSigDataToString(char *szOutput, long nOutChars, const char *szFileIn, long nOptions);
If successful, the return value is a positive number indicating the number of bytes in the content; otherwise it returns a negative error code.
Public Function cmsReadSigDataToString
(szFileIn As String, Optional nOptions As Long = 0) As String
Cms.ReadSigDataToString Method
static Cms.read_sigdata_to_string(inputfile)
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.
This function extracts the signed data from the signed-data CMS object without making any attempt to verify it.
The buffer must be large enough to receive the entire output or a SHORT_BUF_ERROR
error will result.
Use this only when the signed content is known to be plain ASCII text, otherwise use CMS_ReadSigDataToBytes.
This example reads the content from the signed CMS object from example 4.2 in [SMIME-EX].
Dim nRet As Long Dim strFileIn As String Dim strData As String Dim nDataLen As Long strFileIn = "4.2.bin" ' How long is the content to be read? nDataLen = CMS_ReadSigDataToString("", 0, strFileIn, 0) If nDataLen <= 0 Then Exit Function End If ' Pre-dimension string to receive data strData = String(nDataLen, " ") nRet = CMS_ReadSigDataToString(strData, nDataLen, strFileIn, 0) Debug.Print "CMS_ReadSigDataToString returns " & nRet Debug.Print "Data is [" & strData & "]"
This should result in the output:
CMS_ReadSigDataToString returns 28 Data is [This is some sample content.]
Dim strHexDigest As String Dim strData As String Const strCMSFile As String = "4.2.bin" ' Extract the digest value strHexDigest = cmsGetSigDataDigest(strCMSFile, "") Debug.Print "extracted digest=[" & strHexDigest & "]" ' Extract content from signed-data file strData = cmsReadSigDataToString(strCMSFile) Debug.Print "content='" & strData & "'" ' Compute digest value over the content Debug.Print "computed digest =[" & hashHexFromBytes(StrConv(strData, vbFromUnicode), PKI_HASH_SHA1) & "]"
CMS_ReadSigData CMS_ReadSigDataToBytes CMS_GetSigDataDigest