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
Public-Key Encryption Example in C#Download: Chilkat .NET Assemblies How to public-key encrypt and decrypt a string using a digital certificate in C# 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);
}
|
© 2000-2013 Chilkat Software, Inc. All Rights Reserved.