My form will contain various button, each button is configured to let me login to a location.
Only the first time the button will ask me user and password because it will be store in the registry. For the password it will only be stored hash, the username will be clear.
Next time I'll click the button it will read the hash from the registry and should let me login directly.
I have found this code that use DCPCrypt.
This is my code how I encrypt string:
uses DCPrijndael, DCPsha256;
var
S1, S2: String;
c: TDCP_rijndael;
begin
c := TDCP_rijndael.Create(nil);
try
c.InitStr('MyCustomKey', TDCP_sha256);
S1 := c.EncryptString('First string');
c.Reset;
S2 := c.EncryptString('Second string');
finally
c.Free;
end;
end;
And decrypt:
uses DCPrijndael, DCPsha256;
var
S1, S2: String;
c: TDCP_rijndael;
begin
c := TDCP_rijndael.Create(nil);
try
c.InitStr('MyCustomKey', TDCP_sha256);
S1 := c.DecryptString(SomeEncryptedVariable);
c.Reset;
S2 := c.DecryptString(SomeEncryptedVariable);
finally
c.Free;
end;
end;
One thing I noticed. If you want to encrypt / decrypt next string using the same object, you must first reset this object by "Reset" call. Otherwise, next string will be incorrectly encrypted / decrypted
Compiling it I get error on this line:
var
S1, S2: String; Error is:
Compila il progetto, Destinazione: project1.exe: Codice di uscita 1, Errori: 2
unit1.pas(34,3) Error: Illegal expression
unit1.pas(35,3) Fatal: Syntax error, ";" expected but "identifier S1" found