Fórum Criptografar Arquivo INI #284591
14/06/2005
0
Estou com um problema para fazer a criptografia de arquivos INI.
Tenho um arquivo INI no meu projeto com algumas informações importantes e gostaria que não fosse visível para os usuários fora do sistema.
Criei um objeto descendente do TINIFile com dois procedimentos writeCryptString e ReadCryptString. O problema acontece que dependendo do texto que eu criptografo, o programa se perde para recuperá-lo do INI.
Acredito que seja porque o texto criptografado possua algum caractere que seja reservado ao arquivo INI, como por exemplo o ´=´ que delimita o campo e o valor do campo. Não consigo sair desse impasse.
Alguém tem alguma dica de como posso fazer isso? Alguém já passou por este problema?
Obrigado.
Prgdelphi
Curtir tópico
+ 0Posts
14/06/2005
Delphi32
Até!
Gostei + 0
14/06/2005
Prgdelphi
functionMemoryEncrypt(Src: Pointer; SrcSize: Cardinal; Target: Pointer;
TargetSize: Cardinal; Key: TWordTriple): boolean;
var
pIn, pOut: ^byte;
i: Cardinal;
begin
if SrcSize = TargetSize then
begin
pIn := Src;
pOut := Target;
for i := 1 to SrcSize do
begin
pOut^ := pIn^ xor (Key[2] shr 8);
Key[2] := Byte(pIn^ + Key[2]) * Key[0] + Key[1];
inc(pIn);
inc(pOut);
end;
Result := True;
end
else
Result := False;
end;
function MemoryDecrypt(Src: Pointer; SrcSize: Cardinal; Target: Pointer;
TargetSize: Cardinal; Key: TWordTriple): boolean;
var
pIn, pOut: ^byte;
i: Cardinal;
begin
if SrcSize = TargetSize then
begin
pIn := Src;
pOut := Target;
for i := 1 to SrcSize do
begin
pOut^ := pIn^ xor (Key[2] shr 8);
Key[2] := byte(pOut^ + Key[2]) * Key[0] + Key[1];
inc(pIn);
inc(pOut);
end;
Result := True;
end
else
Result := False;
end;
function TextCrypt(const s: string; Key: TWordTriple; Encrypt: Boolean): string;
var
bOK: Boolean;
begin
SetLength(Result, Length(s));
if Encrypt then
bOK := MemoryEncrypt(PChar(s), Length(s), PChar(Result), Length(Result), Key)
else
bOK := MemoryDecrypt(PChar(s), Length(s), PChar(Result), Length(Result), Key);
if not bOK then
Result := ´´;
end;
function TextEncrypt(const s: string; Key: TWordTriple): string;
begin
Result := TextCrypt(s, Key, True);
end;
function TextDecrypt(const s: string; Key: TWordTriple): string;
begin
Result := TextCrypt(s, Key, False);
end;
Gostei + 0
14/06/2005
Massuda
Um jeito simples de contornar esse problema seria modificar TextEncrypt/TextDecrypt (não testei)...
function TextEncrypt(const s: string; Key: TWordTriple): string; var T: string; I: Integer; begin T := TextCrypt(s, Key, True); Result := ´´; for I := 1 to Length(T) do begin Result := Result + IntToHex(Ord(T[I]), 2); end; end; function TextDecrypt(const s: string; Key: TWordTriple): string; var T: string; I: Integer; begin T := ´´; for I := 1 to Length(S) div 2 do begin T := T + Chr(StrToInt(´$´ + Copy(S, 2*I-1, 2))); end; Result := TextCrypt(T, Key, False); end;
Gostei + 0
14/06/2005
Prgdelphi
Gostei + 0
24/08/2005
Helio Nascimento
function TextEncrypt(const s: string; Key: TWordTriple): string; var T: string; I: Integer; begin T := TextCrypt(s, Key, True); Result := ´´; for I := 1 to Length(T) do begin Result := Result + IntToHex(Ord(T[I]), 2); end; end;
[color=blue:72ea92fdaf]Matsuda[/color:72ea92fdaf]
Voce poderia me informar a unit, pois o D7 não recolhece o TWordTriple.
Obrigado.
Gostei + 0
24/08/2005
Massuda
Gostei + 0
05/09/2005
Prgdelphi
[b:94c3d3241d]type[/b:94c3d3241d] TWordTriple = [b:94c3d3241d]array[/b:94c3d3241d][0..2] [b:94c3d3241d]of[/b:94c3d3241d] Word;
Se quiser posso passar a unit completa que faz essa criptografia. Agora está funcionando perfeitamente.
Gostei + 0
12/09/2010
Walter Junior
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)