PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
Sign an EML using RSA-PSS and SHA-256
See more Email Object Examples
Load the intended signing certificate and its RSA private key from a PFX. Set the signature options on Email and render the final S/MIME message through MailMan. The resulting multipart/signed file can be verified independently. Supply the PFX password through your application’s credential store.
Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Email
oleobject loo_Cert
oleobject loo_Mail
oleobject loo_Rendered
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
li_Success = loo_Email.LoadEml("message.eml")
if li_Success <> 1 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
return
end if
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_Cert.LoadPfxFile("signer.pfx","PFX_PASSWORD")
if li_Success <> 1 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Email
destroy loo_Cert
return
end if
li_Success = loo_Email.SetSigningCert(loo_Cert)
if li_Success <> 1 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
destroy loo_Cert
return
end if
loo_Email.SigningAlg = "pss"
loo_Email.SigningHashAlg = "sha256"
loo_Email.SendSigned = 1
loo_Mail = create oleobject
li_rc = loo_Mail.ConnectToNewObject("Chilkat.MailMan")
loo_Mail.OpaqueSigning = 0
loo_Rendered = create oleobject
li_rc = loo_Rendered.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_Mail.RenderToMimeBd(loo_Email,loo_Rendered)
if li_Success <> 1 then
Write-Debug loo_Mail.LastErrorText
destroy loo_Email
destroy loo_Cert
destroy loo_Mail
destroy loo_Rendered
return
end if
li_Success = loo_Rendered.WriteFile("signed.eml")
if li_Success <> 1 then
Write-Debug "Failed: rendered.WriteFile."
destroy loo_Email
destroy loo_Cert
destroy loo_Mail
destroy loo_Rendered
return
end if
Write-Debug "Saved signed.eml."
destroy loo_Email
destroy loo_Cert
destroy loo_Mail
destroy loo_Rendered