对字符串加密,然后保存到注册表中
字符串加密:
unction cryptstr(const s:string; stype: dword):string;
var
i: integer;
fkey: integer;
begin
result:='';
case stype of
0:
begin
randomize;
fkey := random($ff);
for i:=1 to length(s) do
result := result+chr( ord(s) xor i xor fkey);
result := result + char(fkey);
end;
1:
begin
fkey := ord(s[length(s)]);
for i:=1 to length(s) - 1 do
result := result+chr( ord(s) xor i xor fkey);
end;
end;
读写注册表:
var
Registry: TRegistry;
S : string;
begin
Registry:= TRegistry.Create;
try
begin
Registry.RootKey :=MyRootKey; // HKEY_CURRENT_USER;
Registry.OpenKey(MYOpenKey,false); // Registry.OpenKey('/Software/MachineAdministrator',false);
S := Registry.ReadString(RegKey);
end
finally
begin
Registry.CloseKey;
Registry.Free;
end;
if Trim(S)='' then Result := Default
else Result := S;
end;
end;
procedure htwWriteRegisry(RegKey :string ;asValueTobewrited : string; MyRootKey : Hkey; MyOpenKey :string );
var
Registry: TRegistry;
begin
Registry:= TRegistry.Create;
try
begin
Registry.RootKey :=MyRootKey; // HKEY_CURRENT_USER;
Registry.OpenKey(MyOpenKey,true); //Registry.OpenKey('/Software/MachineAdministrator',true);
Registry.WriteString(RegKey,asValueTobewrited);
end
finally
begin
Registry.CloseKey;
Registry.Free;
end;
end;
end;