CryptoSys PKI examples VB6 to VB.NET

RSA_MakeKeys

Generate a RSA key pair and save as a public key file and PKCS-8 EncryptedPrivateKeyInfo file.

VB6/VBA

Debug.Print "Testing RSA_MakeKeys ..."
Dim nRet As Long
Dim sPublicKeyFile As String
Dim sPrivateKeyFile As String
Dim sPassword As String

sPublicKeyFile = "mykey.pub"
sPrivateKeyFile = "mykey.epk"
sPassword = "password"

' Create a new pair of RSA keys saved as BER-encoded files
Debug.Print "About to create a new RSA key pair..."

nRet = RSA_MakeKeys(sPublicKeyFile, sPrivateKeyFile, 512, _
    PKI_RSAEXP_EQ_3, 50, 1000, sPassword, "", 0, PKI_PBE_MD5_DES)
    
Debug.Print "RSA_MakeKeys returns " & nRet & " (expected 0)"

Output

Testing RSA_MakeKeys ...
About to create a new RSA key pair...
RSA_MakeKeys returns 0 (expected 0)

VB.NET

Console.WriteLine("Testing RSA_MakeKeys ...")
Dim nRet As Integer
Dim sPublicKeyFile As String
Dim sPrivateKeyFile As String
Dim sPassword As String

sPublicKeyFile = "mykey.pub"
sPrivateKeyFile = "mykey.epk"
sPassword = "password"

' Create a new pair of RSA keys saved as BER-encoded files
Console.WriteLine("Testing RSA_MakeKeys ...")
Dim nRet As Integer
Dim sPublicKeyFile As String
Dim sPrivateKeyFile As String
Dim sPassword As String

sPublicKeyFile = "mykey.pub"
sPrivateKeyFile = "mykey.epk"
sPassword = "password"

' Create a new pair of RSA keys saved as BER-encoded files
Console.WriteLine("About to create a new RSA key pair...")

nRet = Rsa.MakeKeys(sPublicKeyFile, sPrivateKeyFile, 512, Rsa.PublicExponent.Exp_EQ_3, _
                    1000, sPassword, Rsa.PbeOptions.PbeWithMD5AndDES_CBC, False)

Console.WriteLine("RSA_MakeKeys returns " & nRet & " (expected 0)")

Remarks

This example is just for test purposes. The key length at 512 bits is too short for a production key and the PbeWithMD5AndDES_CBC algorithm is insecure for an encrypted private key.

[Contents]

[HOME]   [NEXT: RSA_RawPrivate...]

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