Sample code for 30+ languages & platforms
PowerBuilder

Load a Public Key from a String

Demonstrates the Chilkat PublicKey.LoadFromString method, which loads a public key from a string. The only argument is the string. Chilkat examines the content and recognizes PEM public keys, unencrypted PEM private keys (taking only the public portion), XML, JWK, and more.

Background: This is the forgiving text loader: rather than requiring you to know the exact format, it inspects whatever string you provide and figures it out. A useful convenience is that it accepts an unencrypted private key too and keeps only the public half — handy when you have a key pair but need just the public key. Use it whenever the textual format is uncertain or varies by source.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_PubKey
string ls_KeyText

li_Success = 0

//  Demonstrates the PublicKey.LoadFromString method, which loads a public key from a string.  The
//  only argument is the string.  Chilkat examines the content and recognizes PEM public keys,
//  unencrypted PEM private keys (using only the public portion), XML, JWK, and more.

loo_PubKey = create oleobject
li_rc = loo_PubKey.ConnectToNewObject("Chilkat.PublicKey")
if li_rc < 0 then
    destroy loo_PubKey
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  The PEM text of a public key.
ls_KeyText = "-----BEGIN PUBLIC KEY-----~nMIIBIjANBgkq...IDAQAB~n-----END PUBLIC KEY-----"

li_Success = loo_PubKey.LoadFromString(ls_KeyText)
if li_Success = 0 then
    Write-Debug loo_PubKey.LastErrorText
    destroy loo_PubKey
    return
end if

Write-Debug "Loaded a " + loo_PubKey.KeyType + " public key."


destroy loo_PubKey