C# Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



C# Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML to XML
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...
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

Public-Key Encryption Example in C#

How to public-key encrypt and decrypt a string using a digital certificate in C#

Download C# Project Files and Source Code

This is a simple example demonstrating how to public-key encrypt and decrypt a string in C#.

// Encrypt text using a digital certificate (i.e. public key encryption)
// The public-key associated with the certificate is needed to encrypt,
// but to decrypt, the private key must be available.
private void PKEncrypt_Click(object sender, System.EventArgs e)
{
	String s = "This string is to be encrypted.";
	listBox1.Items.Add(s);
	
	Chilkat.Crypt crypt = new Chilkat.Crypt();
	crypt.UnlockComponent("UnlockCode");

	// Use RSA public-key encryption.
	crypt.SetAlgorithmRSA();

	// Tell Chilkat Crypt to find and use the first certificate found
	// where one of the certificate's subject fields matches the
	// string passed here.
	crypt.EncryptCertSubject = "harry@chilkatsoft.com";

 // Encrypt and convert the result bytes to Base-64.
	byte [] encryptedBytes = crypt.EncryptStr(s);
	String encrypted = crypt.EncodeBase64(encryptedBytes);

	textBox1.Text = encrypted;

	// Display the last certificate subject and algorithm used.
	listBox1.Items.Add(crypt.LastCertSubject);
	listBox1.Items.Add(crypt.LastAlgorithm);

	// Now decrypt...
	String originalText = crypt.DecryptStr(crypt.DecodeBase64(encrypted));
	listBox1.Items.Add(originalText);
}
 

Need a specific example? Send a request to support@chilkatsoft.com

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

Email Component · XML Parser