Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Delphi ActiveXDelphi DLLVisual FoxProJavaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerShellPythonRubySQL ServerUnicode CUnicode C++Visual Basic 6.0VB.NETVBScript

Classic ASP Examples

Certificates
Email Object
Encryption
FTP
HTML-to-XML/Text
Gzip
HTTP
IMAP
MHT / HTML Email
PFX/P12
Java KeyStore (JKS)
POP3
RSA Encryption
MIME
SMTP
Socket/SSL/TLS
SSH Key
SSH
SFTP
Tar Archive
XML
XMP
Zip

More Examples...
Amazon S3
Bounced Email
CSV
Diffie-Hellman
DKIM / DomainKey
NTLM

 

 

 

 

 

 

 

Public-Key Encryption / Decryption using Certificate

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.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.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.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-2014 Chilkat Software, Inc. All Rights Reserved.