CryptoSys PKI Pro Manual

Example: Rsa.KeyBits  Rsa.RawPrivate  Rsa.RawPublic  Rsa.ReadPrivateKey  Rsa.ReadPublicKey 

[VB6 equivalent: RSA_RawPrivate]

Dim strEPKFile As String
Dim strPubFile As String
Dim strPassword As String
Dim sbPublicKey As StringBuilder
Dim sbPrivateKey As StringBuilder
Dim abData() As Byte
Dim sHexData As String

strEPKFile = "rsa508.p8e"
strPassword = "password"

' Read in the deciphered private key string
sbPrivateKey = Rsa.ReadPrivateKey(strEPKFile, strPassword)
If sbPrivateKey.Length = 0 Then
    Console.WriteLine("Unable to retrieve private key")
    Exit Sub
End If
Console.WriteLine("PriKey length= " & Rsa.KeyBits(sbPrivateKey.ToString()) & " bits")

' Create some raw data to be RSA'd
' Ref: 3.2 Signing the CertificationRequestInfo encoding
' 64-octet EB in full:
'00 01 ff ff ff ff ff ff ff ff ff ff ff ff ff ff
'ff ff ff ff ff ff ff ff ff ff ff ff ff 00 30 20
'30 0c 06 08 2a 86 48 86 f7 0d 02 02 05 00 04 10
'dc a9 ec f1 c1 5c 1b d2 66 af f9 c8 79 93 65 cd

sHexData = "0001ffffffffffffffffffffffffffff" & _
    "ffffffffffffffffffffffffff003020" & _
    "300c06082a864886f70d020205000410" & _
    "dca9ecf1c15c1bd266aff9c8799365cd"

abData = Cnv.FromHex(sHexData)
Console.WriteLine("Input:  " & Cnv.ToHex(abData))

' Now we have our data in a byte array and
' our private key in string format,
' we are ready to do a "raw" operation
abData = Rsa.RawPrivate(abData, sbPrivateKey.ToString)
Console.WriteLine("RSA_RawPrivate returns " & abData.Length)
If abData.Length = 0 Then
    Console.WriteLine("ERROR: " & General.LastError())
Else
    ' Display our results in hex format
    Console.WriteLine("Output: " & Cnv.ToHex(abData))
End If

' Get the corresponding Public Key, also in a file
strPubFile = "rsa508.pub"
sbPublicKey = Rsa.ReadPublicKey(strPubFile)
Console.WriteLine("PubKey length= " & Rsa.KeyBits(sbPublicKey.ToString()) & " bits")

' Do a "raw" encryption with the public key
abData = Rsa.RawPublic(abData, sbPublicKey.ToString(), 0)
Console.WriteLine("RSA_RawPublic returns " & abData.Length)
If abData.Length = 0 Then
    Console.WriteLine("ERROR: " & General.LastError())
Else
    ' Display our results in hex format
    Console.WriteLine("Decrypt:" & Cnv.ToHex(abData))
End If

See Also:
Rsa.RawPrivate Method (Byte[], String)
Rsa.RawPrivate Method (Byte[], String, Int32)

[Contents] [Index]

[PREV: Example: Rsa.MakeKeys ...]   [Contents]   [Index]   
   [NEXT: Example: Rsa.KeyBits ...]

Copyright © 2004-23 D.I. Management Services Pty Ltd. All rights reserved. Generated 2023-09-18T10:02:53Z.