Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Delphi ActiveXDelphi DLLVisual FoxProJavaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerShellPythonRubySQL ServerUnicode CUnicode C++Visual Basic 6.0VB.NETVBScript

C# Examples

Certificates
Email Object
Encryption
FTP
HTML-to-XML/Text
Gzip
HTTP
IMAP
MHT / HTML Email
POP3
RSA Encryption
MIME
SMTP
Socket/SSL/TLS
SSH Key
SSH
SFTP
Tar Archive
XML
XMP
Zip

More Examples...
Amazon S3
Bounced Email
CSV
Diffie-Hellman
DKIM / DomainKey
NTLM

 

 

 

 

 

 

 

Blowfish Encryption / Decryption

Download: Chilkat .NET Assemblies

C# example source code showing how to do 256-bit blowfish encryption and decryption.

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

	public static byte[] StrToByteArray(string str)
	{
		System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();
		return encoding.GetBytes(str);
	}

	private void button1_Click(object sender, System.EventArgs e)
	{
		Chilkat.Crypt crypt = new Chilkat.Crypt();
		crypt.UnlockComponent("UnlockCode");

		// Generate some data.
		String fileContents = "Test\n";
		int i;
		for (i=0; i<100; i++)
		{
			fileContents = fileContents + "This is a test 1234\n";
		}
		byte [] byteData = StrToByteArray(fileContents);
		textBox1.Text = "Data Length = " + Convert.ToString(byteData.Length);

		// Set our algorithm and key-length
		crypt.SetAlgorithmBlowfish();
		crypt.KeyLength = 256;		// 256-bit encryption.
		// Set our password.
		crypt.SetSecretKeyViaPassPhrase("myPassword");
		// Encrypt the data.
		byte [] encryptedData = crypt.Encrypt(byteData);
		textBox1.Text = textBox1.Text + "\r\nEncrypted Length = " + Convert.ToString(encryptedData.Length);

		// Write the encrypted binary file.
		System.IO.BinaryWriter bw = new System.IO.BinaryWriter(
			System.IO.File.Create("encrypted.dat"));
		bw.Write(encryptedData);
		bw.Close();

		// Now read the binary file
		System.IO.FileInfo fInfo = new System.IO.FileInfo("encrypted.dat");

		System.IO.BinaryReader br = new System.IO.BinaryReader(
			System.IO.File.OpenRead("encrypted.dat"));
		byte [] eBytes = br.ReadBytes((int)fInfo.Length);
		br.Close();

		// Decrypt the bytes.
		byte [] dBytes = crypt.Decrypt(eBytes);
		string str = "";
		System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
		str = enc.GetString(dBytes);
		textBox1.Text = textBox1.Text + "\r\n" + str;

	}
}

 

 

 

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