PowerBuilder
PowerBuilder
MIME S/MIME Signing Algorithm Properties
See more MIME Examples
Demonstrates the properties that control S/MIME signing: SigningAlg (the RSA signature scheme, PKCS1-V1_5 or RSASSA-PSS), SigningHashAlg (the message-digest algorithm), Micalg and Protocol (the micalg and protocol parameters of a multipart/signed Content-Type), and UseXPkcs7 (whether historical x-pkcs7 media-type names are used). The properties are configured before creating a detached signature.
Background. These settings determine how the CMS/PKCS #7 signature is produced and how a multipart/signed wrapper advertises it. The defaults (PKCS1-V1_5, sha256) suit most modern uses; the properties allow interoperability with specific requirements.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mime
string ls_PfxPassword
oleobject loo_Cert
li_Success = 0
loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime")
if li_rc < 0 then
destroy loo_Mime
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Mime.SetBodyFromPlainText("This message will be signed.")
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
return
end if
// SigningAlg is the RSA signature scheme. The default is PKCS1-V1_5; set RSASSA-PSS (or pss) for
// RSASSA-PSS.
loo_Mime.SigningAlg = "PKCS1-V1_5"
// SigningHashAlg is the message-digest algorithm. The default is sha256.
loo_Mime.SigningHashAlg = "sha256"
// Micalg and Protocol are the micalg and protocol parameters written into a multipart/signed
// Content-Type header field. They are normally set automatically, but can be controlled here.
loo_Mime.Micalg = "sha-256"
loo_Mime.Protocol = "application/pkcs7-signature"
// UseXPkcs7 controls whether newly created S/MIME media types use the historical x-pkcs7 names.
loo_Mime.UseXPkcs7 = 0
// Load a signing certificate (with private key access) from a PFX. The PFX password should come
// from a secure source rather than being hard-coded.
ls_PfxPassword = "myPfxPassword"
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_Cert.LoadPfxFile("qa_data/signer.pfx",ls_PfxPassword)
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Mime
destroy loo_Cert
return
end if
// Create the detached signature using the algorithms configured above.
li_Success = loo_Mime.AddDetachedSignature(loo_Cert)
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
destroy loo_Cert
return
end if
Write-Debug "Signed with SigningAlg=" + loo_Mime.SigningAlg + " SigningHashAlg=" + loo_Mime.SigningHashAlg
destroy loo_Mime
destroy loo_Cert