Chilkat HOME Android™ ASP Visual Basic VB.NET C# iOS (IPhone) Objective-C C++ C Unicode C++ Unicode C MFC Delphi DLL Delphi ActiveX FoxPro Java Perl PHP Extension PHP ActiveX Python PowerShell Ruby SQL Server VBScript
Encrypt Credit Card Numbers in C#Download: Chilkat .NET Assemblies How
to encrypt and decrypt credit card numbers 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.