PowerShell Requires Chilkat v11.0.0+
PowerShell
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 PowerShell Downloads
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"
$success = $false
# Assumes Chilkat is unlocked. See Global Unlock Sample.
$email = New-Object Chilkat.Email
$success = $email.LoadEml("message.eml")
if ($success -ne $true) {
$($email.LastErrorText)
exit
}
$cert = New-Object Chilkat.Cert
$success = $cert.LoadPfxFile("signer.pfx","PFX_PASSWORD")
if ($success -ne $true) {
$($cert.LastErrorText)
exit
}
$success = $email.SetSigningCert($cert)
if ($success -ne $true) {
$($email.LastErrorText)
exit
}
$email.SigningAlg = "pss"
$email.SigningHashAlg = "sha256"
$email.SendSigned = $true
$mail = New-Object Chilkat.MailMan
$mail.OpaqueSigning = $false
$rendered = New-Object Chilkat.BinData
$success = $mail.RenderToMimeBd($email,$rendered)
if ($success -ne $true) {
$($mail.LastErrorText)
exit
}
$success = $rendered.WriteFile("signed.eml")
if ($success -ne $true) {
$("Failed: rendered.WriteFile.")
exit
}
$("Saved signed.eml.")