C# Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CUnicode C++Unicode CMFCDelphi DLLDelphi ActiveXFoxProJavaPerlPHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C# Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

3DES Public-Key Encryption using Digital Certificates

Download: Chilkat .NET Assemblies

C# source code showing how to do 3DES public-key encryption and decryption.

	// Create an instance of the Chilkat encryption class.
	Chilkat.Crypt2 crypt = new Chilkat.Crypt2(); 

	// Any code begins the 30-day trial.
	crypt.UnlockComponent("30-day-trial"); 

	// Use public-key encryption.
	crypt.CryptAlgorithm = "PKI";

	// Use 3DES encryption.
	Chilkat.Csp csp = new Chilkat.Csp();
	csp.SetProviderMicrosoftEnhanced();
	csp.SetEncryptAlgorithm("3DES");
	crypt.SetCSP(csp);

	// Load a certificate from a .cer file
	// There are many other ways of loading a certificate...
	Chilkat.Cert cert = new Chilkat.Cert();
	bool success = cert.LoadFromFile("myCert.cer");
	if (!success)
	{
		MessageBox.Show(cert.LastErrorText);
		return;
	}

	// Tell the crypt object to use the certificate.
	crypt.SetEncryptCert(cert);

	// Tell the crypt object to base-64 encode the encrypted data.
	crypt.EncodingMode = "base64";

	// File a byte array to encrypt
	byte[] inputData = new byte[10];
	int i;
	for (i=0; i<10; i++)
	{
		inputData[i] = (byte)i;
	}

	// Encrypt the byte array.
	// To encrypt, only the public-key is needed (when using PKI).
	string eStr;
	eStr = crypt.EncryptBytesENC(inputData);
	if (eStr.Length == 0)
	{
		MessageBox.Show(crypt.LastErrorText);
		return;
	}

	MessageBox.Show("Data encrypted: " + eStr);

	// Now decrypt...
	// To decrypt, the private key is needed.  If this step fails but the encryption succeeded,
	// it is probably because the public key is installed and accessible, but not the private key.
	byte[] decrypted;
	decrypted = crypt.DecryptBytesENC(eStr);

	MessageBox.Show("Decrypted length = " + Convert.ToString(decrypted.Length));

	if (decrypted.Length == 0) 
	{
		MessageBox.Show(crypt.LastErrorText);
	}
	else
	{
		for (i=0; i<decrypted.Length; i++)
		{
			if (decrypted[i] != i) 
			{
				MessageBox.Show("Error in decrypted data!");
			}
		}
	}


Important: The download for this example does not contain the ChilkatDotNet.dll which
must be downloaded and installed separately at http://www.chilkatsoft.com/downloads.asp.
Once installed, add a reference to the DLL in the project by following the instructions at
http://www.example-code.com/vbdotnet/step2.asp

 

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