PowerBuilder
PowerBuilder
MIME S/MIME Encryption Algorithm Properties
See more MIME Examples
Demonstrates the properties that control S/MIME encryption: Pkcs7CryptAlg (the symmetric content-encryption algorithm), Pkcs7KeyLength (the content-encryption key length in bits), OaepPadding (whether RSAES-OAEP key transport is used instead of RSAES-PKCS1-v1_5), and the OAEP hash settings OaepHash and OaepMgfHash. The properties are configured before calling Encrypt.
Background. CMS/PKCS #7 encryption uses a symmetric algorithm to protect the content and an RSA key-transport scheme to protect the symmetric key. The defaults (aes, 128-bit, PKCS1-v1_5 padding) work broadly; these properties tune the algorithms and padding.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mime
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 encrypted.")
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
return
end if
// Pkcs7CryptAlg is the symmetric content-encryption algorithm. Supported values are aes, aes-gcm,
// des, 3des, and rc2. The default is aes.
loo_Mime.Pkcs7CryptAlg = "aes"
// Pkcs7KeyLength is the content-encryption key length in bits. The default is 128.
loo_Mime.Pkcs7KeyLength = 256
// OaepPadding selects the RSA key-transport padding. The default is 0 (RSAES-PKCS1-v1_5).
// Set 1 to use RSAES-OAEP, in which case the OAEP hash settings apply.
loo_Mime.OaepPadding = 1
loo_Mime.OaepHash = "sha256"
loo_Mime.OaepMgfHash = "sha256"
// Load the recipient certificate (public key is sufficient for encrypting).
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_Cert.LoadFromFile("qa_data/recipient.cer")
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Mime
destroy loo_Cert
return
end if
// Encrypt using the algorithm settings configured above.
li_Success = loo_Mime.Encrypt(loo_Cert)
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
destroy loo_Cert
return
end if
Write-Debug "Encrypted with " + loo_Mime.Pkcs7CryptAlg + " " + string(loo_Mime.Pkcs7KeyLength) + "-bit key."
destroy loo_Mime
destroy loo_Cert