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

November 27, 2007

Binary Data in Delphi

Some Chilkat ActiveX methods accept binary byte arrays and/or return binary byte arrays. In Delphi, these are OleVariant’s. The CkData object, found in the ChilkatUtil.dll, can be used as a helper to pass binary data to and receive the binary data results from these methods.

ChilkatUtil.dll can be downloaded from http://www.chilkatsoft.com/preRelease/ChilkatUtil.zip

Here is an RSA ActiveX example that loads RSA binary encrypted data from a file, decrypts it and saves the binary output to a file. The point of this example is to show how the CkData object is instantiated, and how it can be used to load data from a file, save it to a file, pass it to a method, and receive the binary data returned by a method:

unit Unit1;
	
interface
	
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,
  CHILKATRSALib_TLB, CHILKATUTILLib_TLB;
	
type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
	
var
  Form1: TForm1;
	
implementation
	
{$R *.dfm}
	
procedure TForm1.Button1Click(Sender: TObject);
var
rsa: TChilkatRsa;
<strong>encData: TCkData;</strong>
<strong>decData: TCkData;</strong>
	
success: Integer;
privateKey: String;
	
begin
rsa := TChilkatRsa.Create(Self);
	
// Create the CkData objects:
<strong>encData := TCkData.Create(Self);</strong>
<strong>decData := TCkData.Create(Self);</strong>
	
success := rsa.UnlockComponent(’Anything for 30-day trial’);
if (success <> 1) then
  begin
    ShowMessage(’RSA component unlock failed’);
  end;
	
// Omitting the private key, which would typically be an XML string…
  privateKey := ‘…’;
	
rsa.ImportPrivateKey(privateKey);
	
// Load a binary file into encData
encData.LoadFile(’rsa_encrypted_data.dat’);
	
// Pass the contents of encData to DecryptBytes, and load the result into decData
decData.LoadBinary(rsa.DecryptBytes(encData.GetBinary(),1));
	
// Save the decrypted data to a file:
decData.SaveToFile(’decrypted_data.dat’);


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.