Creates an XML string representation of an RSA internal key string with option to add a namespace prefix.
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
long __stdcall RSA_ToXMLStringEx(char *szOutput, long nOutChars, const char *szKeyString, const char *szPrefix, long nOptions);
RSAKeyValue
for public key and RSAKeyPair
for private key)RSAKeyValue
format (instead of W3C RSAKeyPair
)RSAKeyValue
from a private key)hexBinary
formatIf successful, the return value is the number of characters in or required for the output string; otherwise it returns a negative error code.
Public Function rsaToXMLStringEx
(szKeyString As String, szPrefix As String, Optional nOptions As Long = 0) As String
Rsa.ToXMLString Method (String, String, Rsa.XmlOptions)
static Rsa.to_xmlstring(keystr, opts=0, prefix='')
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.
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>
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"