CryptoSys PKI Pro Manual

CMS_ReadSigDataToString

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

VBA/VB6 Syntax

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

C/C++ Syntax

long __stdcall CMS_ReadSigDataToString(char *szOutput, long nOutChars, const char *szFileIn, long nOptions);

Parameters

szOutput
[out] to receive the output.
nOutChars
[in] specifying the length of the output string.
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 cmsReadSigDataToString (szFileIn As String, Optional nOptions As Long = 0) As String

.NET Equivalent

Cms.ReadSigDataToString Method

Python Equivalent

static Cms.read_sigdata_to_string(inputfile)

Remarks

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.

Example (VBA core function)

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.]

Example (VBA wrapper function)

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) & "]"

See Also

CMS_ReadSigData CMS_ReadSigDataToBytes CMS_GetSigDataDigest

[Contents] [Index]

[PREV: CMS_ReadSigDataToBytes...]   [Contents]   [Index]   
   [NEXT: CMS_VerifySigData...]

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