[VB6 equivalent: RSA_PublicKeyFromPrivate]
Dim strPriKeyFile As String
Dim sbPrivateKey As StringBuilder
Dim strPublicKey As String
Dim nCode As Integer
Dim nRet As Integer
' Read private key from encrypted private key file into internal string form
strPriKeyFile = "BobPrivRSAEncrypt.epk"
sbPrivateKey = Rsa.ReadEncPrivateKey(strPriKeyFile, "password")
If sbPrivateKey.Length = 0 Then Exit Sub 'Catch error here
' Display some info about it
Console.WriteLine("Private key length = {0} bits", Rsa.KeyBits(sbPrivateKey.ToString()))
nCode = Rsa.KeyHashCode(sbPrivateKey.ToString())
Console.WriteLine("KeyHashCode={0,8:X}", nCode)
nRet = Rsa.CheckKey(sbPrivateKey)
Console.WriteLine("Rsa.CheckKey returns " & nRet & ": (PKI_VALID_PRIVATEKEY=" & 0 & ")")
' Convert to public key string
strPublicKey = Rsa.PublicKeyFromPrivate(sbPrivateKey).ToString()
If strPublicKey.Length = 0 Then Exit Sub ' Catch error here
' Display some info about it
Console.WriteLine("Public key length = " & Rsa.KeyBits(strPublicKey) & " bits")
nCode = Rsa.KeyHashCode(strPublicKey)
Console.WriteLine("KeyHashCode={0,8:X}", nCode)
nRet = Rsa.CheckKey(strPublicKey)
Console.WriteLine("Rsa.CheckKey returns " & nRet & ": (PKI_VALID_PUBLICKEY=" & 1 & ")")
' Clean up
Wipe.String(sbPrivateKey)
See Also:
Rsa.PublicKeyFromPrivate Method