Sample code for 30+ languages & platforms
Classic ASP

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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

set mime = Server.CreateObject("Chilkat.Mime")
success = mime.SetBodyFromPlainText("This message will be encrypted.")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( mime.LastErrorText) & "</pre>"
    Response.End
End If

'  AddEncryptCert adds one recipient certificate to the list used by EncryptN.  Call it once per
'  recipient.
set cert = Server.CreateObject("Chilkat.Cert")
success = cert.LoadFromFile("qa_data/recipient.cer")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>"
    Response.End
End If

success = mime.AddEncryptCert(cert)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( mime.LastErrorText) & "</pre>"
    Response.End
End If

'  EncryptN then encrypts for all certificates added.
success = mime.EncryptN()
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( mime.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Encrypted for the added recipient(s).") & "</pre>"

%>
</body>
</html>