CryptoSys PKI Toolkit Manual

Example: Rsa.KeyHashCode  Rsa.ReadEncPrivateKey  Rsa.ReadPrivateKeyInfo  Rsa.SaveEncPrivateKey 

[VB6 equivalent: RSA_ReadPrivateKeyInfo]

Dim strPriFile As String
Dim strEPKFile As String
Dim strPrivateKey As String
Dim strPK1 As String
Dim nRet As Integer

' Read in Bob's unencrypted PrivateKeyInfo data
strPriFile = "BobPrivRSAEncrypt.pri"
strPrivateKey = Rsa.ReadPrivateKeyInfo(strPriFile).ToString()
If strPrivateKey.Length = 0 Then
    Console.WriteLine("Failed to read Private Key file")
    Exit Sub
End If
' Now we save it with a password
strEPKFile = "BobPrivRSAEncrypt.epk"
nRet = Rsa.SaveEncPrivateKey(strEPKFile, strPrivateKey, 1000, "password", 0, 0)
Console.WriteLine("RSA_SaveEncPrivateKey returns " & nRet)

' Check we can read it
strPK1 = Rsa.ReadEncPrivateKey(strEPKFile, "password").ToString()

' To compare these strings, use the RSA_KeyHashCode function
Console.WriteLine("{0,8:X}", Rsa.KeyHashCode(strPK1))
Console.WriteLine("{0,8:X}", Rsa.KeyHashCode(strPrivateKey))
If Rsa.KeyHashCode(strPK1) = Rsa.KeyHashCode(strPrivateKey) Then
    Console.WriteLine("Key string values match.")
Else
    Console.WriteLine("ERROR: key strings do not match.")
End If

See Also:
Rsa.ReadPrivateKeyInfo Method

[Contents] [Index]

[HOME]   [NEXT: Example: Rsa.KeyBits ...]

Copyright © 2004-12 D.I. Management Services Pty Ltd. All rights reserved.