请看: http://www.delphibbs.com/delphibbs/dispq.asp?lid=529506
另外,还可以通过针对文件流的随机XOR进行加密,具体的随机数产生方法见:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=622076 (参见我的回答,安全性绝佳!)
//TEA是一种优秀的数据加密算法,虽然它比DES要简单得多,但有很强的抗差分分析能
//力,加密速度也比DES快得多,而且对64位数据加密的密钥长达128位,安全性相当好。
// v[2] : 64bit data, k[4] : 128bit key
var
TEA_a,TEA_b,TEA_c,TEA_d
Word;
procedure InitTEA;
var
Key
DWord;
begin
Key:=@MyCryptKeyBuf[0]; //128Bit长的密钥缓冲区
TEA_a:=Key^;
Inc(DWord(Key),4);
TEA_b:=Key^;
Inc(DWord(Key),4);
TEA_c:=Key^;
Inc(DWord(Key),4);
TEA_d:=Key^;
end;
procedure TEA_Encipher(v
DWord); //参数为待加密缓冲区的指针
var
y,z,Sum,Delta,n
Word;
begin
y:=v^;
z:=PDWord(DWord(v)+SizeOf(DWord))^;
Sum:=0;
Delta:=$9E3779B9;
n:=32;
while n>0 do
begin
Dec
;
Inc(Sum,Delta);
Inc(y,(z shl 4)+TEA_a xor z+sum xor(z shr 5)+TEA_b);
Inc(z,(y shl 4)+TEA_c xor y+sum xor(y shr 5)+TEA_d);
end;
v^:=y;
PDWord(DWord(v)+SizeOf(DWord))^:=z;
end;
procedure TEA_Decipher(v
DWord); //...解密.....
var
y,z,Sum,Delta,n
Word;
begin
y:=v^;
z:=PDWord(DWord(v)+SizeOf(DWord))^;
Sum:=$C6EF3720;
Delta:=$9E3779B9;
n:=32;
while n>0 do
begin
Dec
;
Dec(z,(y shl 4)+TEA_c xor y+sum xor(y shr 5)+TEA_d);
Dec(y,(z shl 4)+TEA_a xor z+sum xor(z shr 5)+TEA_b);
Dec(Sum,Delta);
end;
v^:=y;
PDWord(DWord(v)+SizeOf(DWord))^:=z;
end;
//注:上面的TEA算法仅能对长度为8的整数倍的文件进行加密