我在我的项目中使用crypto api WCrypt2进行md5 crypt,但我不知道要解码。你能给我提供crypto api的解码功能吗?
在我的项目中,我需要使用下面的加密代码。解码功能必须与 Label1 和 Edit1 一起使用。Bouth 包含在表单启动中,但对于解码,我将使用 Button1
这是我的代码:
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.