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

 

 

 

 

 

 

Encrypt Credit Card Numbers in C#

Download: Chilkat .NET Assemblies

How to encrypt and decrypt credit card numbers
or other short strings in C#.

NOTE: This example uses the Chilkat.Crypt class, not Chilkat.Crypt2

This is a simple example demonstrating how to encrypt a short string such as a credit card number to an encrypted string (and decrypt) in C#.

// This C# example shows how to AES encrypt a credit card number
// to produce an encrypted string.  It also decrypts back to
// the original credit card number.  (The credit card number
// in this example is not a valid one, obviously.)
private void AesEncrypt_Click(object sender, System.EventArgs e)
{
	String ccNum = "3488381909007887";
	listBox1.Items.Add(ccNum);

	Chilkat.Crypt crypt = new Chilkat.Crypt();
	crypt.UnlockComponent("UnlockCode");

	// Use AES encryption (the Rijndael algorithm is AES encryption).
	crypt.SetAlgorithmRijndael();

	// Use 256-bit Rijndael encryption.
	crypt.KeyLength = 256;

	// Set a secrety key via a password.
	// To decrypt, we must use the same secret key.
	crypt.SetSecretKeyViaPassPhrase("flubber");

	// Encrypt the credit card number, but convert the binary
	// bytes returned to a base-64 string.
	byte [] encryptedBytes = crypt.EncryptStr(ccNum);
	String encrypted = crypt.EncodeBase64(encryptedBytes);

	listBox1.Items.Add(encrypted);

	// We use a separate Chilkat.Crypt object to demonstrate
	// the requirement that the properties must match those
	// used when encrypting.
	Chilkat.Crypt crypt2 = new Chilkat.Crypt();
	// Use AES encryption (the Rijndael algorithm is AES encryption).
	crypt2.SetAlgorithmRijndael();
	// Use 256-bit Rijndael encryption.
	crypt2.KeyLength = 256;
	// Set a secrety key via a password.
	// To decrypt, we must use the same secret key.
	crypt2.SetSecretKeyViaPassPhrase("flubber");

	// Decode base-64 and decrypt to a string.
	String decrypted = crypt.DecryptStr(crypt.DecodeBase64(encrypted));

	listBox1.Items.Add(decrypted);
}


 

 

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