Welcome to the Xceed Community | Help
Community Search  
More Search Options

Writing public/private/secret keys to text files.

Sort Posts: Previous Next
  •  10-10-2008, 11:05 AM Post no. 28484

    Writing public/private/secret keys to text files.

    The public/private/secret keys created by the Xceed Encryption Library via the SetSecretKeyFromPassPhrase, SetRandomSecretKey or SetRandomKeyPair methods are not strings. The generated keys (which can be retrieved via the SecretKey, PrivateKey and PublicKey properties) must be encoded (using the Xceed Binary Encoding Library for example) BEFORE they can be written to a text file (as text).

    For example:

    ' generate the keys
    rsa.SetRandomKeyPair( 1024, null )

    Dim encoder as XceedBinaryEncoding
    Call encoder.License( "your license key" )

    Dim encodedKey As Variant
    encodedKey = encoder.Encode( rsa.PublicKey, true )

    ' Because the encoded key is returned as a variant we need to convert it
    ' to a string using the ToString method
    Dim writableKey As String
    writableKey = encoder.ToString( encodedKey )

    ' write the writable key to the text file.

    To decode the key, you would need to do the opposite:

    1- Read the writeable key from the text file
    2- Use the FromString method to convert the key back to a variant
    3- Decode the key using the Xceed Binary Encoding's Decode method
    4- Assign the key to the appropriate property (PublicKey, PrivateKey or SecretKey).
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.