CryptoSys PKI Pro Manual

CMS_ReadSigDataToBytes

Reads the content from a CMS signed-data object file directly into a byte array.

VBA/VB6 Syntax

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

C/C++ Syntax

long __stdcall CMS_ReadSigDataToBytes(unsigned char *lpOutput, long nOutBytes, const char *szFileIn, long nOptions);

Parameters

lpOutput
[out] buffer to receive the output.
nOutBytes
[in] length of the output buffer.
szFileIn
[in] with name of signed-data CMS object file (binary or base64-encoded) or the data as a base64 or PEM string.
nOptions
[in] option flags:
PKI_DEFAULT (0) for default options

Returns (VBA/C)

If successful, the return value is a positive number indicating the number of bytes in the content; otherwise it returns a negative error code.

VBA Wrapper Syntax

Public Function cmsReadSigDataToBytes (szFileIn As String, Optional nOptions As Long = 0) As Byte()

.NET Equivalent

Cms.ReadSigDataToBytes Method

C++ (STL) Equivalent

static bvec_t dipki::Cms::ReadSigDataToBytes (const std::string &inputFile)

Python Equivalent

static Cms.read_sigdata_to_bytes(inputfile)

Remarks

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.

Example (VBA core function)

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)

Example (VBA wrapper function)

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 & "'"

See Also

CMS_ReadSigData CMS_ReadSigDataToString CMS_GetSigDataDigest

[Contents] [Index]

[PREV: CMS_ReadSigData...]   [Contents]   [Index]   
   [NEXT: CMS_ReadSigDataToString...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.