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

 

 

 

Public-Key Encryption / Decryption using Certificate

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

This ASP script shows how to use a digital certificate for encryption and decryption.

<html>
<head>
<title>ASP to Public-Key Encrypt / Decrypt a String</title>
</head>
<body>
<%
' First, locate a certificate to use for public-key encryption.
' (There are many ways to instantiate a digital certificate.
' Please review the digital certificate examples for more information.)

' Get an object to create a certificate store object
set ccs = Server.CreateObject("Chilkat_9_5_0.CreateCS")

' Open the local machine certificate store.
set certStore = ccs.OpenLocalSystemStore()

' Find the certificate matching the email address "matt@chilkatsoft.com"
set cert = certStore.FindCertBySubjectE("matt@chilkatsoft.com")
if (cert is Nothing) then
	Response.write "Certificate not found!"
else
	Response.write "Using certificate: " & cert.SubjectDN & "<br>"
	
	' Create a Chilkat encryption instance to do the public-key encryption.
	set crypt = Server.CreateObject("Chilkat_9_5_0.Crypt2")
	
	' Any value passed to UnlockComponent begins the 30-day trial.
	unlocked = crypt.UnlockComponent("30-day trial")
	if unlocked then

		' Use the digital certificate...
		crypt.SetEncryptCert cert

		crypt.CryptAlgorithm = "pki"
		
		stringToEncrypt = "This is a test"
		
		' Public-key encrypt the string and
		' convert the encrypted byte data to a hexidecimalized string.
		crypt.EncodingMode = "hex"
		encryptedString = crypt.EncryptStringENC(stringToEncrypt)
		
		Response.write "(1) Encrypted Data:<br>" & encryptedString & "<br><br>"
		
		' Display the details of the encryption
		' Notice that we probably used 40-bit RC2 encryption.
		' Next we will use the Chilkat CSP object to select stronger encryption.
		Response.write crypt.LastErrorHtml & "<br><br>"
		
		' Select the enhanced Microsoft provider with 3DES
		set csp = Server.CreateObject("Chilkat_9_5_0.Csp")
		csp.SetProviderMicrosoftEnhanced
		' Select 168-bit 3DES encryption
		csp.SetEncryptAlgorithm "3DES"
		crypt.SetCSP(csp)
		
		' Now re-do the public-key encryption.
		encryptedString = crypt.EncryptStringENC(stringToEncrypt)
		
		Response.write "(2) Encrypted Data:<br>" & encryptedString & "<br><br>"
		
		' Display the details of the encryption
		Response.write crypt.LastErrorHtml & "<br><br>"
		
		' Now decrypt it...
		' Decrypting requires the private key to be installed on the computer
		' and accessible from ASP.
		decryptedString = crypt.DecryptStringENC(encryptedString)
		
		Response.write "Decrypted: [" & decryptedString & "]<br><br>"
		
		' Show the details of the decryption.
		Response.write crypt.LastErrorHtml & "<br><br>"
		
	end if
	
end if


%>
</body>
</html>

 

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