Sample code for 30+ languages & platforms
PowerBuilder

Load a Public Key from Base64 DER

Demonstrates the Chilkat PublicKey.LoadBase64 method, which loads a public key from standard Base64-encoded DER. The only argument is the Base64 string; whitespace within it is permitted.

Background: A public key in DER (binary) form is often carried as Base64 text so it can travel through channels that expect a string — a config value, a JSON field, a certificate export. This loader decodes that text and inspects the DER to determine the key type and structure automatically. It is the plain-Base64 counterpart to loading a full PEM block, which additionally has the BEGIN/END armor.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_PubKey
string ls_KeyStr

li_Success = 0

//  Demonstrates the PublicKey.LoadBase64 method, which loads a public key from standard
//  Base64-encoded DER.  The only argument is the Base64 string (whitespace is allowed).

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 Base64 of the DER-encoded public key.
ls_KeyStr = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...IDAQAB"

li_Success = loo_PubKey.LoadBase64(ls_KeyStr)
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