PowerBuilder
PowerBuilder
RSA Encrypt with Modulus and Exponent
See more RSA Examples
Demonstrates how to RSA encrypt with a given modulus and exponent.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rsa
string ls_Modulus
string ls_Exponent
oleobject loo_Xml
oleobject loo_PubKey
integer li_UsePrivateKey
string ls_PlainText
string ls_EncryptedStrBase64
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
// Assuming you already have a base64 modulus and exponent,
// wrap it in XML like this:
ls_Modulus = "qMBRpdYrAy5aMmo31NErUizh5sbweguSmh4wlK6uJEIDl+kwTlROnE34KOFExeTbJSX0WygPi+vWl0yNq7buIMUKpytossAAWut5khO3CQJxTk7G2gnEPNUUXHiExGgNrLzcSLv8YIlfVALhoRWyC67KOL+a+3taNq3h+BHeWhM="
ls_Exponent = "AQAB"
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
loo_Xml.Tag = "RSAPublicKey"
loo_Xml.NewChild2("Modulus",ls_Modulus)
loo_Xml.NewChild2("Exponent",ls_Exponent)
loo_PubKey = create oleobject
li_rc = loo_PubKey.ConnectToNewObject("Chilkat.PublicKey")
li_Success = loo_PubKey.LoadFromString(loo_Xml)
if li_Success = 0 then
Write-Debug loo_PubKey.LastErrorText
destroy loo_Rsa
destroy loo_Xml
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_Xml
destroy loo_PubKey
return
end if
li_UsePrivateKey = 0
ls_PlainText = "message in a bottle"
loo_Rsa.EncodingMode = "base64"
ls_EncryptedStrBase64 = loo_Rsa.EncryptStringENC(ls_PlainText,li_UsePrivateKey)
Write-Debug ls_EncryptedStrBase64
destroy loo_Rsa
destroy loo_Xml
destroy loo_PubKey