Sample code for 30+ languages & platforms
PowerBuilder

Load PEM Public/Private Key into RSA Object

See more RSA Examples

Demonstrates how to load a PEM key into the Chilkat RSA object.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Rsa
string ls_PublicKeyPem
oleobject loo_Pubkey
string ls_PrivateKeyPem
oleobject loo_Privkey

li_Success = 0

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

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

// First demonstrate importing a PEM public key:
ls_PublicKeyPem = "PEM public-key data goes here"
loo_Pubkey = create oleobject
li_rc = loo_Pubkey.ConnectToNewObject("Chilkat.PublicKey")

li_Success = loo_Pubkey.LoadFromString(ls_PublicKeyPem)
if li_Success = 0 then
    Write-Debug loo_Pubkey.LastErrorText
    destroy loo_Rsa
    destroy loo_Pubkey
    return
end if

li_Success = loo_Rsa.UsePublicKey(loo_Pubkey)
if li_Success = 0 then
    Write-Debug loo_Rsa.LastErrorText
    destroy loo_Rsa
    destroy loo_Pubkey
    return
end if

// Demonstrate importing a PEM private key:
ls_PrivateKeyPem = "PEM private-key data goes here"
loo_Privkey = create oleobject
li_rc = loo_Privkey.ConnectToNewObject("Chilkat.PrivateKey")

// If the private key PEM is protected with a password, then 
// call LoadEncryptedPem.  Otherwise call LoadPem.
li_Success = loo_Privkey.LoadPem(ls_PrivateKeyPem)
if li_Success = 0 then
    Write-Debug loo_Privkey.LastErrorText
    destroy loo_Rsa
    destroy loo_Pubkey
    destroy loo_Privkey
    return
end if

li_Success = loo_Rsa.UsePrivateKey(loo_Privkey)
if li_Success = 0 then
    Write-Debug loo_Rsa.LastErrorText
    destroy loo_Rsa
    destroy loo_Pubkey
    destroy loo_Privkey
    return
end if

Write-Debug "OK!"


destroy loo_Rsa
destroy loo_Pubkey
destroy loo_Privkey