I use crypto api WCrypt2 in my project for md5 crypt but i dont know to decode. Can you provide me the decode function for crypto api?
In my project i need to use this encryption code from bellow. The decode function must work with the Label1 and Edit1.Bouth are included in form startup, but for decode i will use a Button1
here is my code:
unit HUID;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdGlobal, IdHash, IdHashMessageDigest, WCrypt2;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetEnvVarValue(const VarName: string): string;
var
BufSize: Integer; // buffer size required for value
begin
// Get required buffer size (inc. terminal #0)
BufSize := GetEnvironmentVariable(PChar(VarName), nil, 0);
if BufSize > 0 then
begin
// Read env var value into result string
SetLength(Result, BufSize - 1);
GetEnvironmentVariable(PChar(VarName),
PChar(Result), BufSize);
end
else
// No such environment variable
Result := '';
end;
function md5(const Input: string): string;
var
i: Integer;
pbContent: PByte;
dwHashBytes: Cardinal;
hHash: HCRYPTHASH;
hCryptProvider: HCRYPTPROV;
bHash: array[0..$7f] of Byte;
begin
Result := '';
dwHashBytes := 16;
pbContent := Pointer(PChar(Input));
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) * sizeof(Char), 0) then
begin
if CryptGetHashParam(hHash, HP_HASHVAL, @bHash[0], @dwHashBytes, 0) then
begin
for i := 0 to dwHashBytes - 1 do
begin
Result := Result + Format('%.2x', [bHash[i]]);
end;
end;
end;
CryptDestroyHash(hHash);
end;
CryptReleaseContext(hCryptProvider, 0);
end;
Result := AnsiLowerCase(Result);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Label1.Caption := (GetEnvVarValue('PROCESSOR_REVISION')+GetEnvVarValue('PROCESSOR_LEVEL')+GetEnvVarValue('NUMBER_OF_PROCESSORS')+GetEnvVarValue('Cor_Debugging_Control_424242'));
Edit1.Text := md5(Label1.Caption);
end;
end.
MD5 is a one-way hash.
It is used for signing information and checking passwords.
Encryption
If you want to encrypt data (eg to send it securely across the wire) You need to use a cipher like AES or 3DES.
If you replace the MD5 call with AES decryption becomes easy.
AES is a symmetric cipher, meaning that encryption and decryption uses the same key (although not the same operation).
See the following wiki pages for more info:
Signing
If you want to use the MD5 function for password encryption, then you're making two mistakes:
In order to check a password you rehash it using the same salt and check to see if the same result comes out.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.