Creates an XML string representation of an RSA internal key string.
VB6/VBA
Debug.Print "Testing RSA_ToXMLString ..." Dim strEPKFile As String Dim strPassword As String Dim strPrivateKey As String Dim strXML As String Dim nLen As Long strEPKFile = "AlicePrivRSASign.epk" strPassword = "password" ' Read in the deciphered private key string in our internal format strPrivateKey = rsaReadPrivateKey(strEPKFile, strPassword) If Len(strPrivateKey) = 0 Then MsgBox "Unable to retrieve private key" Exit Sub End If Debug.Print "Key size=" & RSA_KeyBits(strPrivateKey) & " bits" ' Convert to XML nLen = RSA_ToXMLString("", 0, strPrivateKey, PKI_XML_RSAKEYVALUE) ' pre-dimension first strXML = String(nLen, " ") nLen = RSA_ToXMLString(strXML, Len(strXML), strPrivateKey, PKI_XML_RSAKEYVALUE) strXML = Left(strXML, nLen) Debug.Print "XML=" & strXML
Output
Testing RSA_ToXMLString ... Key size=1024 bits XML=<RSAKeyValue><Modulus>4IlzOY3Y9fXoh3Y5f06wBbtTg94Pt6vcfcd1KQ0FLm0S36aGJtTSb6 pYKfyX7PqCUQ8wgL6xUJ5GRPEsu9gyz8ZobwfZsGCsvu40CWoT9fcFBZPfXro1Vtlh/xl/yYHm+Gzqh0 Bw76xtLHSfLfpVOrmZdwKmSFKMTvNXOFd0V18=</Modulus><Exponent>AQAB</Exponent><P>9tbg IiFMXwpw/yf85bNQap3lD7WFlsZA+qgKtJubDFXCAR35N4KKFMjykw6SzaVmIbk80ga/tFUxydytypgt 0Q==</P><Q>6N6wESUJ0gJRAd6K6JhQ9Xd3YaRFk2sIVZZzXfTIWxKTInOLf9Nwf/Wkqrt0/Twiato4k SqGW2wU6K5MnvqOLw==</Q><DP>l0zwh5sXf+4bgxsUtgtqkF+GJ1Hht6B/9eSI41m5+R6b0yl3OCJI1 yKxJZi6PVlTt/oeILLIURYjdZNR56vN8Q==</DP><DQ>LPAkW/qgzYUi6tBuT/pszSHTyOTxhERIZHPX KY9+RozsFd7kUbOU5yyZLVVleyTqo2IfPmxNZ0ERO+G+6YMCgw==</DQ><InverseQ>WIjZoVA4hGqrA 7y730v0nG+4tCol+/bkBS9u4oiJIW9LJZ7Qq1CTyr9AcewhJcV/+wLpIZa4M83ixpXub41fKA==</Inv erseQ><D>pAPDJ0d2NDRspoa1eUkBSy6K0shissfXSAlqi5H3NvJ11ujNFZBgJzFHNWRNlc1nY860n1a sLzduHO4Ovygt9DmQbzTYbghb1WVq2EHzE9ctOV7+M8v/KeQDCz0Foo+38Y6idjeweVfTLyvehwYifQR mXskbr4saw+yRRKt/IQ==</D></RSAKeyValue>
VB.NET
Console.WriteLine("Testing RSA_ToXMLString ...")
Dim strEPKFile As String
Dim strPassword As String
Dim strPrivateKey As String
Dim strXML As String
strEPKFile = "AlicePrivRSASign.epk"
strPassword = "password"
' Read in the deciphered private key string in our internal format
strPrivateKey = Rsa.ReadEncPrivateKey(strEPKFile, strPassword).ToString()
If Len(strPrivateKey) = 0 Then
Console.WriteLine("Unable to retrieve private key")
Exit Sub
End If
Console.WriteLine("Key size=" & Rsa.KeyBits(strPrivateKey) & " bits")
' Convert to XML
strXML = Rsa.ToXMLString(strPrivateKey, Rsa.XmlOptions.ForceRSAKeyValue)
Console.WriteLine("XML=" & strXML)
Remarks
[Contents]