Uma das melhores criptografias existentes no momento, a md5 e inquebrável ela só criptografa mais não descriptografa, sendo que é uma segurança a mais para o usuário e para o dono do software, pois pode ser usada em varias ocasiões, eu mesmo utilizo e aprovo, então vim postar aqui para vocês esta função, se caso não conseguirem usar eu dou uma ajuda só postar um comentário ai.
Obs : para que essa function possa funcionar precisa ter :
Código.:
function TForm1.md5(const Input: String): String;
var
hCryptProvider: HCRYPTPROV;
hHash: HCRYPTHASH;
bHash: array[0..$7f] of Byte;
dwHashLen: DWORD;
pbContent: PByte;
i: Integer;
begin
dwHashLen := 16;
pbContent := Pointer(PChar(Input));
Result := '';
if CryptAcquireContext(@hCryptProvider, nil, nil, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT or CRYPT_MACHINE_KEYSET) then
begin
if CryptCreateHash(hCryptProvider, CALG_MD5, 0, 0, @hHash) then
begin
if CryptHashData(hHash, pbContent, Length(Input), 0) then
begin
if CryptGetHashParam(hHash, HP_HASHVAL, @bHash[0], @dwHashLen, 0) then
begin
for i := 0 to dwHashLen - 1 do
begin
Result := Result + Format('%.2x', [bHash[i]]);
end;
end;
end;
CryptDestroyHash(hHash);
end;
CryptReleaseContext(hCryptProvider, 0);
end;
Result := AnsiLowerCase(Result);
end;
A unit Wcrypt2.pas. no link abaixo você encontra a unit necessária http://stuff.irsoft.de/CryptoAPI2.zip |
Código.:
function TForm1.md5(const Input: String): String;
var
hCryptProvider: HCRYPTPROV;
hHash: HCRYPTHASH;
bHash: array[0..$7f] of Byte;
dwHashLen: DWORD;
pbContent: PByte;
i: Integer;
begin
dwHashLen := 16;
pbContent := Pointer(PChar(Input));
Result := '';
if CryptAcquireContext(@hCryptProvider, nil, nil, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT or CRYPT_MACHINE_KEYSET) then
begin
if CryptCreateHash(hCryptProvider, CALG_MD5, 0, 0, @hHash) then
begin
if CryptHashData(hHash, pbContent, Length(Input), 0) then
begin
if CryptGetHashParam(hHash, HP_HASHVAL, @bHash[0], @dwHashLen, 0) then
begin
for i := 0 to dwHashLen - 1 do
begin
Result := Result + Format('%.2x', [bHash[i]]);
end;
end;
end;
CryptDestroyHash(hHash);
end;
CryptReleaseContext(hCryptProvider, 0);
end;
Result := AnsiLowerCase(Result);
end;
Bom pessoal então era isso que eu queria estar compartilhando com vocês, ate a próxima postagem
0 comentários:
Postar um comentário