Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Classic ASP Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

Encrypt File to .p7m

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

ASP example program to encrypt a file to produce a .p7m as output. A digital certificate (public-key) is used for encrypting.

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

set crypt = Server.CreateObject("Chilkat_9_5_0.Crypt2")

'  Any string argument automatically begins the 30-day trial.
success = crypt.UnlockComponent("30-day trial")
If (success <> 1) Then
    Response.Write "Crypt component unlock failed" & "<br>"

End If

'  Use public-key encryption with a digital certificate:
crypt.CryptAlgorithm = "pki"

'  There are many ways to select and load a digital certificate.
'  Certs can be retrieved from the Windows registry-based
'  certificate stores, from database tables, files, etc.
'  This example will load a .cer file.
set cert = Server.CreateObject("Chilkat_9_5_0.Cert")

success = cert.LoadFromFile("myCert.cer")
If (success <> 1) Then
    Response.Write cert.LastErrorText & "<br>"

End If

crypt.SetEncryptCert cert

'  The CkEncryptFile can encrypt files of any size.  The
'  encryption occurs in streaming mode, so it is not necessary
'  to hold the entire contents of the file in memory at once.
success = crypt.CkEncryptFile("dude.gif","dude.p7m")
If (success <> 1) Then
    Response.Write crypt.LastErrorText & "<br>"

End If

'  To decrypt the file, you'll need the private key.
'  Also, the certificate should have already been installed
'  on the computer.  This is typically achieved by installing
'  from a .pfx file, or by importing from a certificate
'  authority's online web application.  If you are decrypting
'  from ASP, ASP.NET, or a Windows Service, you'll need to
'  import in a way that provides the calling process permission
'  to access and use the private key.  The procedure for
'  doing this is explained here:
'  http://blog.chilkatsoft.com/?p=149
' 
'  Also, there is no "SetDecryptCert" method.  The .p7m
'  contains information that allows the Chilkat component
'  to locate the certificate to be used for decryption.
'  The Chilkat Crypt component automatically searches
'  the Windows Current User certificate store and the
'  Local Machine certificate store.
success = crypt.CkDecryptFile("dude.p7m","dudeOut.gif")
If (success <> 1) Then
    Response.Write crypt.LastErrorText & "<br>"

End If


%>
</body>
</html>

 

© 2000-2026 Chilkat Software, Inc. All Rights Reserved.