Sample code for 30+ languages & platforms
PowerBuilder

RSA Encrypt and OpenSSL Decrypt

See more OpenSSL Examples

Demonstrates how to use Chilkat to RSA encrypt, and then use OpenSSL to decrypt.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Rsa
oleobject loo_PrivKey
oleobject loo_PubKey
string ls_PlainText
integer li_BUsePrivateKey
string ls_EncryptedStr
oleobject loo_Bd

li_Success = 0

// This requires 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

loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")

li_Success = loo_Rsa.GenKey(2048,loo_PrivKey)
li_Success = loo_PrivKey.SavePkcs8PemFile("qa_output/privKey.pem")

loo_PubKey = create oleobject
li_rc = loo_PubKey.ConnectToNewObject("Chilkat.PublicKey")

loo_PrivKey.ToPublicKey(loo_PubKey)

loo_Rsa.EncodingMode = "base64"
ls_PlainText = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890"
li_BUsePrivateKey = 0
loo_Rsa.UsePublicKey(loo_PubKey)
ls_EncryptedStr = loo_Rsa.EncryptStringENC(ls_PlainText,li_BUsePrivateKey)

loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")

loo_Bd.AppendEncoded(ls_EncryptedStr,"base64")
li_Success = loo_Bd.WriteFile("qa_output/enc.dat")

// The OpenSSL command to decrypt is:
// openssl pkeyutl -in enc.dat -inkey privKey.pem -keyform PEM -pkeyopt rsa_padding_mode:pkcs1 -decrypt

Write-Debug "OK"


destroy loo_Rsa
destroy loo_PrivKey
destroy loo_PubKey
destroy loo_Bd