Reads the content from a CMS signed-data object file directly into a byte array.
Public Declare Function CMS_ReadSigDataToBytes Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByVal strFileIn As String, ByVal nOptions As Long) As Long
nRet = CMS_ReadSigDataToBytes(lpOutput(0), nOutBytes, strFileIn, nOptions) As Long
long __stdcall CMS_ReadSigDataToBytes(unsigned char *lpOutput, long nOutBytes, 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 cmsReadSigDataToBytes
(szFileIn As String, Optional nOptions As Long = 0) As Byte()
static bvec_t dipki::Cms::ReadSigDataToBytes (const std::string &inputFile)
static Cms.read_sigdata_to_bytes(inputfile)
This function extracts the signed content from the signed-data CMS object without making any attempt to verify it.
Call the function with a NULL abOutput array or zero nOutBytes parameter to find out the required length of
the output buffer.
The buffer must be large enough to receive the entire output or a SHORT_BUF_ERROR
error will result.
Use this function if the content contains non-ASCII characters such as UTF-8 encoded.
This example reads the content from the signed CMS object created in the example for
CMS_MakeSigDataFromBytes
.
Dim nRet As Long Dim strSigDataFile As String Dim abData() As Byte Dim nBytes As Long strSigDataFile = "basicsignedbyalice_utf8.p7m" Debug.Print "Reading signed-data file '" & strSigDataFile & "'" ' How long is the content to be read? nBytes = CMS_ReadSigDataToBytes(ByVal 0&, 0, strSigDataFile, 0) Debug.Print "CMS_ReadSigDataToBytes returns " & nBytes If nBytes <= 0 Then Exit Function End If ' Dimension byte array to receive data ReDim abData(nBytes - 1) nBytes = CMS_ReadSigDataToBytes(abData(0), nBytes, strSigDataFile, 0) ' Display extracted content in hex Debug.Print "HEX(data)=" & cnvHexStrFromBytes(abData) & " (" & UBound(abData) + 1 & " bytes)"
This should result in the output:
Reading signed-data file 'basicsignedbyalice_utf8.p7m' CMS_ReadSigDataToBytes returns 38 HEX(data)=3C646F633E3C6E616D6520633D276573273EC38DC3B169676F3C2F6E616D653E3C2F646F633E (38 bytes)
Dim lpData() As Byte Dim strData As String ' Read UTF-8 encoded data from signed-data CMS object lpData = cmsReadSigDataToBytes("basicsignedbyalice_utf8.p7m") Debug.Assert cnvBytesLen(lpData) > 0 Debug.Print "HEX(CONTENT)=" & cnvHexStrFromBytes(lpData) ' Convert from UTF-8-encoded bytes to VB Unicode string strData = cnvLatin1FromUTF8Bytes(lpData) Debug.Print "CONTENT='" & strData & "'"
CMS_ReadSigData CMS_ReadSigDataToString CMS_GetSigDataDigest