Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

December 19, 2006

AES Encrypt Delphi / Java Interop

One advantage to using the Chilkat Crypt component is that the identical API spans many programming languages: VB6, C#, VB.NET, Delphi, C++, FoxPro, ASP, Java, Ruby, Perl, Python, etc. (Actually, this applies to all the Chilkat components.)

A recent support email asked how to AES encrypt in Delphi, and decrypt in Java with both sides using the Chilkat encryption component. Here is the sample code:

Delphi Encryption Code

	
procedure TForm1.Button3Click(Sender: TObject);
var
  encrypted: string;
begin
  // ChilkatCrypt21 is an instance of ChilkatCrypt2
  // that we dropped onto our form.
  ChilkatCrypt21.UnlockComponent('test');
	
    ChilkatCrypt21.CryptAlgorithm  := 'rijndael';
    ChilkatCrypt21.CipherMode := 'cbc';
    ChilkatCrypt21.KeyLength := 128;
    ChilkatCrypt21.EncodingMode := 'base64';
    ChilkatCrypt21.SecretKey := ChilkatCrypt21.GenerateSecretKey('myPassword');
	
    encrypted := ChilkatCrypt21.EncryptStringENC('This string is to be encrypted');
	
    // Displays: cZLpHHyRILPmgdLF0ZauLK/2++YO/uBfPPkQl/WS9u0=
    Edit1.Text := encrypted;
	
end;

Java Decryption Code

	
CkCrypt2 crypt = new CkCrypt2();
crypt.UnlockComponent("anything for 30-day trial");
	
crypt.put_CryptAlgorithm("aes");
crypt.put_CipherMode("cbc");
crypt.put_KeyLength(128);
crypt.put_EncodingMode("base64");
	
CkByteData secretKey = new CkByteData();
crypt.GenerateSecretKey("myPassword",secretKey);
crypt.put_SecretKey(secretKey);
	
CkString decrypted = new CkString();
crypt.DecryptStringENC("cZLpHHyRILPmgdLF0ZauLK/2++YO/uBfPPkQl/WS9u0=",decrypted);
	
// Displays: This string is to be encrypted
System.out.println(decrypted.getString());
	


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.