CryptoSys PKI Pro Manual

RSA_ToXMLStringEx

Creates an XML string representation of an RSA internal key string with option to add a namespace prefix.

VBA/VB6 Syntax

Public Declare Function RSA_ToXMLStringEx Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strKeyString As String, ByVal strPrefix As String, ByVal nOptions As Long) As Long

nRet = RSA_ToXMLStringEx(strOutput, nOutChars, strKeyString, "ds", nOptions) As Long

C/C++ Syntax

long __stdcall RSA_ToXMLStringEx(char *szOutput, long nOutChars, const char *szKeyString, const char *szPrefix, long nOptions);

Parameters

szOutput
[out] to receive XML data.
nOutChars
[in] specifying the maximum number of characters to be received.
szKeyString
[in] containing the RSA public or private key in internal format
szPrefix
[in] the namespace prefix to be added to all elements
nOptions
[in] option flags: Select and combine:
PKI_DEFAULT (0) to output in appropriate W3C standard format (RSAKeyValue for public key and RSAKeyPair for private key)
PKI_XML_RSAKEYVALUE to force private key output as .NET-compatible RSAKeyValue format (instead of W3C RSAKeyPair)
PKI_XML_EXCLPRIVATE to exclude the private key (use to get a public key RSAKeyValue from a private key)
PKI_XML_HEXBINARY to output with data in non-conforming hexBinary format

Returns (VBA/C)

If successful, the return value is the number of characters in or required for the output string; otherwise it returns a negative error code.

VBA Wrapper Syntax

Public Function rsaToXMLStringEx (szKeyString As String, szPrefix As String, Optional nOptions As Long = 0) As String

.NET Equivalent

Rsa.ToXMLString Method (String, String, Rsa.XmlOptions)

Python Equivalent

static Rsa.to_xmlstring(keystr, opts=0, prefix='')

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.

Use this extended function to add a namespace prefix to all elements in the XML output; for example, <ds:RSAKeyValue>. Note that it's up to the user to map the prefix to a URI somewhere in the final XML document (for reference, the correct form is xmlns:ds="http://www.w3.org/2000/09/xmldsig#").

See also the remarks for RSA_ToXMLString.

Example (VBA core function)

nLen = RSA_ToXMLStringEx("", 0, strPrivateKey, "ds", PKI_XML_EXCLPRIVATE)
' pre-dimension first
strXML = String(nLen, " ")
nLen = RSA_ToXMLStringEx(strXML, Len(strXML), strPrivateKey, "ds", PKI_XML_EXCLPRIVATE)
strXML = Left(strXML, nLen)    
Debug.Print "XML=" & strXML
<ds:RSAKeyValue><ds:Modulus>uV3GoY7...Yb+F3Q==</ds:Modulus><ds:Exponent>AQAB</ds:Exponent></ds:RSAKeyValue>

Example (VBA wrapper function)

Dim strPrivateKey As String
strPrivateKey = rsaReadPrivateKey("AlicePrivRSASign.p8e", "password")
Debug.Print rsaToXMLString(strPrivateKey, 0)
Debug.Print rsaToXMLString(strPrivateKey, PKI_XML_EXCLPRIVATE Or PKI_XML_HEXBINARY)
Debug.Print rsaToXMLStringEx(strPrivateKey, "ds", PKI_XML_EXCLPRIVATE)
' Now derive internal private key string from XML
Dim strXML As String
Dim strKey As String
strXML = rsaToXMLString(strPrivateKey)
strKey = rsaFromXMLString(strXML)
Debug.Print "Key length = " & RSA_KeyBits(strKey) & " bits"

See Also

RSA_ToXMLString

[Contents] [Index]

[PREV: RSA_ToXMLString...]   [Contents]   [Index]   
   [NEXT: SIG_SignData...]

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