Delphi Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
DH Key Exchange
DSA
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
NTLM
POP3
RSA
S/MIME
SMTP
Socket
Spider
SFTP
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Amazon S3
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

Type Conversion

 

Article: Understanding COM References in Delphi

Match Java JCE AES Encryption Results (ECB mode)

Download Chilkat Crypt ActiveX

Shows sample code in Delphi that matches Java JCE encryption results for 128-bit AES encryption using ECB mode.

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,
    CHILKATCRYPT2Lib_TLB,
    OleCtrls;

...

procedure TForm1.Button1Click(Sender: TObject);
var
crypt: TChilkatCrypt2;
success: Integer;
password: String;
secretKeyHex: String;
text: String;
encText: String;

begin
crypt := TChilkatCrypt2.Create(Self);

// Any string argument automatically begins the 30-day trial.
success := crypt.UnlockComponent('30-day trial');
if (success <> 1) then
  begin
    ShowMessage('Crypt component unlock failed');

  end;

password := 'secretPassphrase';

// Use the Digest MD5 algorithm to get a 16-byte binary secret key.
crypt.HashAlgorithm := 'md5';
crypt.EncodingMode := 'hex';
secretKeyHex := crypt.HashStringENC(password);

crypt.CryptAlgorithm := 'aes';
crypt.CipherMode := 'ecb';
crypt.KeyLength := 128;
crypt.SetEncodedKey(secretKeyHex,'hex');

text := 'The quick brown fox jumped over the lazy dog.';
encText := crypt.EncryptStringENC(text);

// Displays:
// C960892077D566258D38DF4BBAE8548E6827BF8C27A9D2EE
// 6F563FC75003F8F6A05B54CFD28CDC8833BD073F7FC6D031
Memo1.Lines.Add(encText);

// This Java (JCE) code produces the same results:
// String password = "secretPassphrase";
// 
// MessageDigest md = MessageDigest.getInstance("MD5");
// md.update(password.getBytes("UTF-8"), 0, password.length());
// byte[] rawKey = md.digest();
// 
// String text = "The quick brown fox jumped over the lazy dog.";
// 
// SecretKeySpec skeySpec = new SecretKeySpec(rawKey, "AES");
// Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
// cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
// 
// byte[] encrypted = cipher.doFinal(text.getBytes("UTF-8"));
// 
// System.out.println(toHex(encrypted));

// This is the toHex method in Java:
// public static String toHex (byte buf[]) {
// 
// StringBuffer strbuf = new StringBuffer(buf.length * 2);
// int i;
// 
// for (i = 0; i < buf.length; i++) {
// if (((int) buf[i] & 0xff) < 0x10)
// strbuf.append("0");
// 
// strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
// }
// 
// return strbuf.toString();
// }

end;

 

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

Mail Component · .NET Email Component · XML Parser