Delphi Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Delphi Examples

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

More Examples...
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate

Unreleased...
Bzip2
LZW
Icon

Type Conversion

 

Article: Understanding COM References in Delphi

AES Encryption to Match PHP's Mcrypt Extension

Demonstrates how to match AES encryption results with PHP's mcrypt extension.

Please refer to this discussion about PHP AES Encryption. The code here matches the PHP mcrypt results on that page.

Download Chilkat Crypt ActiveX

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

...

procedure TForm1.Button1Click(Sender: TObject);
var
crypt: TChilkatCrypt2;
success: Integer;
ivAscii: String;
keyAscii: String;
plainText: String;
cipherText: String;

begin
crypt := TChilkatCrypt2.Create(Self);

success := crypt.UnlockComponent('Anything for 30-day trial');
if (success <> 1) then
  begin
    ShowMessage('Crypt component unlock failed');

  end;

//  AES is also known as Rijndael.
crypt.CryptAlgorithm := 'aes';

//  CipherMode may be "ecb" or "cbc"
crypt.CipherMode := 'cbc';

//  KeyLength may be 128, 192, 256
crypt.KeyLength := 256;

//  Pad with NULL bytes (PHP pads with NULL bytes)
crypt.PaddingScheme := 3;

//  EncodingMode specifies the encoding of the output for
//  encryption, and the input for decryption.
//  It may be "hex", "url", "base64", or "quoted-printable".
crypt.EncodingMode := 'hex';

ivAscii := '1234567890123456';
crypt.SetEncodedIV(ivAscii,'ascii');

//  The secret key must equal the size of the key.  For
//  256-bit encryption, the binary secret key is 32 bytes.
//  For 128-bit encryption, the binary secret key is 16 bytes.
keyAscii := '12345678901234561234567890123456';
crypt.SetEncodedKey(keyAscii,'ascii');

plainText := 'The quick brown fox jumped over the lazy dog';

cipherText := crypt.EncryptStringENC(plainText);
ShowMessage(cipherText);

//  Do 128-bit AES encryption:
crypt.KeyLength := 128;
keyAscii := '1234567890123456';
crypt.SetEncodedKey(keyAscii,'ascii');

cipherText := crypt.EncryptStringENC(plainText);
ShowMessage(cipherText);

//  -------
//  Results
//  -------
//  You may use these as test vectors for testing your AES implementations...
// 
//  ------------------------
//  256-bit key, CBC mode
//  ------------------------
//  IV = '1234567890123456' 
//   (hex: 31323334353637383930313233343536)
//  Key = '12345678901234561234567890123456' 
//   (hex: 3132333435363738393031323334353631323334353637383930313233343536)
//  PlainText:
//   'The quick brown fox jumped over the lazy dog'
	// CipherText(hex):
//   2fddc3abec692e1572d9b7d629172a05caf230bc7c8fd2d26ccfd65f9c54526984f7cb1c4326ef058cd7bee3967299e3

// 
//  ------------------------
//  128-bit key, CBC mode
//  ------------------------
//  IV = '1234567890123456' 
//   (hex: 31323334353637383930313233343536)
//  Key = '1234567890123456' 
//   (hex: 31323334353637383930313233343536)
//  PlainText:
//   'The quick brown fox jumped over the lazy dog'
	// CipherText(hex):
//   f78176ae8dfe84578529208d30f446bbb29a64dc388b5c0b63140a4f316b3f341fe7d3b1a3cc5113c81ef8dd714a1c99

end;

 

Need a specific example? Send a request to support@chilkatsoft.com

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

Mail Component · .NET Email Component · XML Parser