PowerBuilder Requires Chilkat v11.8.0+
PowerBuilder
Open an RSA-OAEP and AES-128-CBC message
See more Email Object Examples
Read the output of the matching encryption example. Chilkat takes the algorithm parameters from the CMS envelope. Give it the recipient’s private key, then read the recovered subject and body only after decryption succeeds.
Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Email
oleobject loo_Pem
li_Success = 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
destroy loo_Email
MessageBox("Error","Connecting to COM object failed")
return
end if
// The recipient's certificate and private key are in a PEM file. The 2nd argument of LoadPemFile
// is the password of the private key.
loo_Pem = create oleobject
li_rc = loo_Pem.ConnectToNewObject("Chilkat.Pem")
li_Success = loo_Pem.LoadPemFile("recipient.pem","PEM_PASSWORD")
if li_Success <> 1 then
Write-Debug loo_Pem.LastErrorText
destroy loo_Email
destroy loo_Pem
return
end if
li_Success = loo_Email.AddPemSource(loo_Pem)
if li_Success <> 1 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
destroy loo_Pem
return
end if
li_Success = loo_Email.LoadEml("oaep-encrypted.eml")
if li_Success <> 1 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
destroy loo_Pem
return
end if
if loo_Email.ReceivedEncrypted <> 1 then
Write-Debug "The input has no S/MIME encryption layer."
destroy loo_Email
destroy loo_Pem
return
end if
if loo_Email.Decrypted <> 1 then
Write-Debug "Could not decrypt with the available private keys."
destroy loo_Email
destroy loo_Pem
return
end if
Write-Debug "Subject: " + loo_Email.Subject
if loo_Email.HasPlainTextBody() = 1 then
Write-Debug loo_Email.GetPlainTextBody()
end if
li_Success = loo_Email.SaveEml("oaep-decrypted.eml")
if li_Success <> 1 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
destroy loo_Pem
return
end if
Write-Debug "Saved oaep-decrypted.eml."
destroy loo_Email
destroy loo_Pem