Componentes.Terceros.RemObj.../internal/5.0.23.613/1/RemObjects SDK for Delphi/Source/RODEC/uROCiphers.pas
david 2824855ea7 - Modificación del paquete RemObjects_Core_D10 para que sea un paquete de runtime/designtime (antes era designtime sólo)
- Recompilación en Delphi10 de todos los paquetes de RO para generar las DCU's en Lib\D10
- Recompilación en Delphi10 de todos los paquetes de DA para generar las DCU's en Lib\D10

git-svn-id: https://192.168.0.254/svn/Componentes.Terceros.RemObjects@9 b6239004-a887-0f4b-9937-50029ccdca16
2007-09-10 14:06:19 +00:00

68 lines
1.7 KiB
ObjectPascal

unit uROCiphers;
interface
uses
Windows, SysUtils, Classes, uroCipher, uroCipher1, uroHash, uroDECUtil;
type
TROBaseCipher = class(TObject)
public
procedure EncryptStream(const Plaintext, Ciphertext: TStream); virtual; abstract;
procedure DecryptStream(const Ciphertext, Plaintext: TStream); virtual; abstract;
end;
TRODECCipher = class(TROBaseCipher)
protected
fCipher: TROCipher;
public
constructor Create(aCipherClass: TROCipherClass; aKey: string);
destructor Destroy; override;
procedure EncryptStream(const Plaintext, Ciphertext: TStream); override;
procedure DecryptStream(const Ciphertext, Plaintext: TStream); override;
end;
implementation
{ TRODECCipher }
constructor TRODECCipher.Create(aCipherClass: TROCipherClass; aKey: string);
var
i : Integer;
keyval : string;
begin
fCipher := aCipherClass.Create('', nil);
fCipher.Mode := cmCTS;
fCipher.HashClass := TROHash_RipeMD256;
i := Length(aKey) div 2;
if i > fCipher.KeySize then
i := fCipher.KeySize;
//convert key to binary
keyval := formattostr(PChar(aKey), Length(aKey), fmthex);
fCipher.Init(keyval[1], i, nil);
end;
procedure TRODECCipher.DecryptStream(const Ciphertext, Plaintext: TStream);
begin
fCipher.CodeStream(Ciphertext, Plaintext, Ciphertext.Size - Ciphertext.Position, paDecode);
end;
destructor TRODECCipher.Destroy;
begin
fCipher.Free;
inherited;
end;
procedure TRODECCipher.EncryptStream(const Plaintext, Ciphertext: TStream);
begin
//Plaintext.seek(0, soFromBeginning);
fCipher.CodeStream(Plaintext, Ciphertext, Plaintext.Size, paEncode);
end;
end.