Tcl
Tcl
Add a Recipient Certificate for S/MIME Encryption
See more MIME Examples
Demonstrates AddEncryptCert, which adds one recipient certificate to the list used by EncryptN. Call it once for each intended recipient, then call EncryptN to encrypt for all of them.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background. AddEncryptCert builds up the recipient list used by EncryptN. Only the public key of each certificate is required for encryption.
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
set mime [new_CkMime]
set success [CkMime_SetBodyFromPlainText $mime "This message will be encrypted."]
if {$success == 0} then {
puts [CkMime_lastErrorText $mime]
delete_CkMime $mime
exit
}
# AddEncryptCert adds one recipient certificate to the list used by EncryptN. Call it once per
# recipient.
set cert [new_CkCert]
set success [CkCert_LoadFromFile $cert "qa_data/recipient.cer"]
if {$success == 0} then {
puts [CkCert_lastErrorText $cert]
delete_CkMime $mime
delete_CkCert $cert
exit
}
set success [CkMime_AddEncryptCert $mime $cert]
if {$success == 0} then {
puts [CkMime_lastErrorText $mime]
delete_CkMime $mime
delete_CkCert $cert
exit
}
# EncryptN then encrypts for all certificates added.
set success [CkMime_EncryptN $mime]
if {$success == 0} then {
puts [CkMime_lastErrorText $mime]
delete_CkMime $mime
delete_CkCert $cert
exit
}
puts "Encrypted for the added recipient(s)."
delete_CkMime $mime
delete_CkCert $cert