Sample code for 30+ languages & platforms
Classic ASP

Encrypt MIME using PEM Certificate

See more MIME Examples

Encrypt MIME using a PEM certificate.

Chilkat Classic ASP Downloads

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

' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.

set mime = Server.CreateObject("Chilkat.Mime")

' Create a simple MIME message to be encrypted:
success = mime.AddHeaderField("Content-Type","text/plain")
success = mime.AddHeaderField("abc","123")
mime.SetBody "This is a test"

set cert = Server.CreateObject("Chilkat.Cert")
success = cert.LoadFromFile("qa_data/pem/mf_public_rsa.pem")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>"
    Response.End
End If

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

' Display the MIME:
Response.Write "<pre>" & Server.HTMLEncode( mime.GetMime()) & "</pre>"

' The resulting S/MIME looks like this:

' Content-Type: application/x-pkcs7-mime; name="smime.p7m"; smime-type="enveloped-data"
' abc: 123
' Content-Disposition: attachment; filename="smime.p7m"
' Content-Transfer-Encoding: base64
' 
' MIICMAYJKoZIhvcNAQcDoIICITCCAh0CAQAxggGoMIIBpAIBADCBizB3MQswCQYDVQQGEwJQTDEi
' MCAGA1UEChMZVW5pemV0byBUZWNobm9sb2dpZXMgUy5BLjEnMCUGA1UECxMeQ2VydHVtIENlcnRp
' ZmljYXRpb24gQXV0aG9yaXR5MRswGQYDVQQDExJDZXJ0dW0gTGV2ZWwgSVYgQ0ECEDVuXbie8bb5
' sHeajm5k3ZYwDQYJKoZIhvcNAQEBBQAEggEADNac7gEUOvTWfyqwe0cS+m65Lte7ZmDGRElvqeo7
' C2+JZJfuxl2Roy+4vTovnn+9U2Yf5Kqc1m2ZPCE5Q8ExvOV4M0cTocLNLK6sfCR7cvo1xgf220qf
' XYqWF1/ePuP9j1FrkFvBOoS4BREAnXsEa4zvuhvNPsMfjInK8wWnMftbLUiriAZBq391D+dxxX8M
' kB1EHCWaS3H8WQI/caTnkRS6YdOCOrctJHtotkcU+4gcIxfTcq6yeloceURbesAYAvdRbIGszKCQ
' FA2sC1x8SkDQCHfNUvmyS/fmkq5waFpmq1ksOspInb4ZM7SOjEUu+22vkAgbTmOS3MUdieuRcTBs
' BgkqhkiG9w0BBwEwHQYJYIZIAWUDBAECBBClRoHLQZyzdHwoZA6pZjLYgEChuMzbQRXOjNF3RpnI
' ZjNTKFDuhaUqk0rRTTn3D89F7ZMUBtoCP0bw+bH5UE9zpDaAgCF9s3W3/D5YNgAuw4AZ

%>
</body>
</html>