CryptoSys PKI examples VB6 to VB.NET

RSA_FromXMLString

Creates an RSA key string in internal format from an XML string.

VB6/VBA

Debug.Print "Testing RSA_FromXMLString ..."
Dim strInternalKey As String
Dim strXML As String
Dim nLen As Long
Dim nRet As Long

strXML = "<RSAKeyValue>" _
& "<Modulus>CmZ5HcaYgWjeerd0Gbt/sMABxicQJwB1FClC4ZqNjFH" _
& "QU7PjeCod5dxa9OvplGgXARSh3+Z83Jqa9V1lViC7qw==</Modulus>" _
& "<Exponent>AQAB</Exponent>" _
& "</RSAKeyValue>"

nLen = RSA_FromXMLString("", 0, strXML, 0)
If nLen <= 0 Then
    MsgBox ("Error: " & nLen)
    Exit Sub
End If
strInternalKey = String(nLen, " ")
nLen = RSA_FromXMLString(strInternalKey, Len(strInternalKey), strXML, 0)
strInternalKey = Left(strInternalKey, nLen)

Debug.Print "INTKEY=" & strInternalKey

nRet = RSA_CheckKey(strInternalKey, 0)
Debug.Print "RSA_CheckKey returns " & nRet

Output

Testing RSA_FromXMLString ...
INTKEY=PUBRjGO6cqCgTRhEXJCOjUWNagyqWaKeaggjXsHKGs1Q6Gr6k6agawaaJMVBawqiWH4Vd3H3MPa4xRa0/nlGXvLGlCq4hoOsKk01IdrO2NiJ8sXgykCG9WxWrloKaemmi8OB
RSA_CheckKey returns 1

VB.NET

Console.WriteLine("Testing RSA_FromXMLString ...")
Dim strInternalKey As String
Dim strXML As String
Dim nRet As Integer

strXML = "<RSAKeyValue>" _
    & "<Modulus>CmZ5HcaYgWjeerd0Gbt/sMABxicQJwB1FClC4ZqNjFH" _
    & "QU7PjeCod5dxa9OvplGgXARSh3+Z83Jqa9V1lViC7qw==</Modulus>" _
    & "<Exponent>AQAB</Exponent>" _
    & "</RSAKeyValue>"

strInternalKey = Rsa.FromXMLString(strXML, False)
If strInternalKey.Length = 0 Then
    Console.WriteLine("Error: ")
    Exit Sub
End If

Console.WriteLine("INTKEY=" & strInternalKey)

nRet = Rsa.CheckKey(strInternalKey)
Console.WriteLine("RSA_CheckKey returns " & nRet)

Remarks

The internal key string is encrypted and is different each time.

[Contents]

[HOME]   [NEXT: RSA_FromXMLString2...]

Copyright © 2010-20 D.I. Management Services Pty Ltd. All rights reserved.