acertij022
20-11-2006, 14:11:48
Hola delphiano hace una semana pedi ayuda para encriptar string en triple-DES y me recomendaron el componente DCPcrypt http://www.cityinthesky.co.uk/cryptography.html
Bueno todo funciona perfecto pero ahora necesito encapsularlo en una DLL para poder usarlo en otros lenguajes. Al intentar levantar la DLL desde Delphi me sale un error (Invalid pointer operation).
El codigo de la DLL es el siguiente:
library des;
uses
SysUtils,
Classes,
DCPcrypt2, DCPblockciphers, DCPdes, DCPsha1;
{$R *.res}
function TripleDes(dato,contrasenia:string;accion:boolean):string; stdcall; overload;
var
Cipher: TDCP_3des;
begin
Cipher:= TDCP_3des.Create(nil);//(Self);
Cipher.InitStr(contrasenia,TDCP_sha1); // initialize the cipher with a hash of the passphrase
if accion=true then Result:= Cipher.EncryptString(dato)
else Result:= Cipher.DecryptString(dato);
Cipher.Burn;
Cipher.Free;
end;
Exports TripleDes(dato,contrasenia:string;accion:boolean);
begin
end.
y el codigo en delphi para levantar la DLL es:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
GroupBox1: TGroupBox;
Memo1: TMemo;
GroupBox2: TGroupBox;
Memo2: TMemo;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TripleDes(dato,contrasenia:string;accion:boolean):string; stdcall; external 'DES.DLL';
procedure TForm1.Button1Click(Sender: TObject);
begin
memo2.Text := TripleDes(memo1.Text,edit1.text,true);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
memo2.Text := TripleDes(memo1.Text,edit1.text,false);
end;
end.
supongo que el error es que uso como parametro NIL en vez de SELF al crear el componente pero si colo este ultimo no me compila([Error] des.dpr(13): Undeclared identifier: 'Self').
Espero que alguien me pueda ayudar desde ya muchas gracias :D
Bueno todo funciona perfecto pero ahora necesito encapsularlo en una DLL para poder usarlo en otros lenguajes. Al intentar levantar la DLL desde Delphi me sale un error (Invalid pointer operation).
El codigo de la DLL es el siguiente:
library des;
uses
SysUtils,
Classes,
DCPcrypt2, DCPblockciphers, DCPdes, DCPsha1;
{$R *.res}
function TripleDes(dato,contrasenia:string;accion:boolean):string; stdcall; overload;
var
Cipher: TDCP_3des;
begin
Cipher:= TDCP_3des.Create(nil);//(Self);
Cipher.InitStr(contrasenia,TDCP_sha1); // initialize the cipher with a hash of the passphrase
if accion=true then Result:= Cipher.EncryptString(dato)
else Result:= Cipher.DecryptString(dato);
Cipher.Burn;
Cipher.Free;
end;
Exports TripleDes(dato,contrasenia:string;accion:boolean);
begin
end.
y el codigo en delphi para levantar la DLL es:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
GroupBox1: TGroupBox;
Memo1: TMemo;
GroupBox2: TGroupBox;
Memo2: TMemo;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TripleDes(dato,contrasenia:string;accion:boolean):string; stdcall; external 'DES.DLL';
procedure TForm1.Button1Click(Sender: TObject);
begin
memo2.Text := TripleDes(memo1.Text,edit1.text,true);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
memo2.Text := TripleDes(memo1.Text,edit1.text,false);
end;
end.
supongo que el error es que uso como parametro NIL en vez de SELF al crear el componente pero si colo este ultimo no me compila([Error] des.dpr(13): Undeclared identifier: 'Self').
Espero que alguien me pueda ayudar desde ya muchas gracias :D