-
Notifications
You must be signed in to change notification settings - Fork 24
/
Cromis.Streams.Filters.XTEA.pas
66 lines (50 loc) · 1.56 KB
/
Cromis.Streams.Filters.XTEA.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
unit Cromis.Streams.Filters.XTEA;
interface
uses
SysUtils, Classes,
// cromis library units
Cromis.Streams, Cromis.XTEA, Cromis.Streams.Filters, Cromis.Unicode;
type
TXTEAFilter = class(TCustomFilter)
private
FKey: TBytes;
public
constructor Create(const Key: TBytes); overload;
constructor Create(const Key: ustring); overload;
procedure InputFilter(const InputStream, OutputStream: TStream); override;
procedure OutputFilter(const InputStream, OutputStream: TStream); override;
end;
// filter data constructor
function XTEAFilter(const Key: TBytes): TCustomFilter; overload;
function XTEAFilter(const Key: ustring): TCustomFilter; overload;
implementation
// filter data constructor
function XTEAFilter(const Key: TBytes): TCustomFilter; overload;
begin
Result := TXTEAFilter.Create(Key);
end;
function XTEAFilter(const Key: ustring): TCustomFilter; overload;
begin
Result := TXTEAFilter.Create(Key);
end;
{ TXTEAFilter }
constructor TXTEAFilter.Create(const Key: TBytes);
begin
FID := '32D80BECF7F64C8890AC6F7469736001';
FKey := Key;
end;
constructor TXTEAFilter.Create(const Key: ustring);
begin
Create(GetBytesFromUnicodeString(Key));
end;
procedure TXTEAFilter.InputFilter(const InputStream, OutputStream: TStream);
begin
inherited;
XTeaEncryptStream(InputStream, OutputStream, FKey);
end;
procedure TXTEAFilter.OutputFilter(const InputStream, OutputStream: TStream);
begin
inherited;
XTeaDecryptStream(InputStream, OutputStream, FKey);
end;
end.