function LockupFile(FileName:string;Lock:boolean=true):integer;
//加密、解密数据库,针对 Access 2000
var
f:File;
bf:array[0..63] of Byte;
i:integer;
const
fpos=64;
flen=64;
//下面改为自己的密钥,我是用随机生成的,请改为自己的密钥
pw:array[0..63] of byte=
($97,$A0,$AC,$61,$16,$59,$2A,$6F,
$91,$33,$51,$57,$D4,$A3,$94,$16,
$3D,$B2,$C8,$A0,$7C,$A6,$30,$EE,
$34,$D6,$9D,$FE,$F6,$EC,$A5,$1F,
$71,$2C,$19,$69,$D3,$25,$5B,$8B,
$D3,$95,$AB,$C9,$02,$8A,$87,$44,
$9F,$C7,$D8,$6D,$BA,$69,$56,$15,
$FA,$CB,$03,$D6,$94,$A6,$BE,$F0);
begin
result:=-1;
if not FileExists(FileName) then exit;
try
AssignFile(f,Filename);
Reset(f,1);
Seek(f,fpos);
BlockRead(f,bf,flen);
//下面的代码是判断是否被加密,你可以用二进制编辑器打开MDB文件对比,
//我是用第64,65字节作为是否加密的标记,未加密与版本相关,加密后与版本和密钥相关
if lock and (bf[0]=$2B) and (bf[1]=$EE)
or not lock and (bf[0]=$BC) and (bf[1]=$4E)
or not ((bf[0]=$2B) and (bf[1]=$EE))
and not ((bf[0]=$BC) and (bf[1]=$4E)) then
begin
result:=0;
exit;
end;
for i:=0 to flen-1 do
bf:=bf xor pw[i mod 64];
Seek(f,fpos);
BlockWrite(f,bf,flen);
result:=1;
finally
CloseFile(f);
end;
end;