I watched what MSTSC does with a debugger, the description is always psw.
Here's the cleaned up function:
Delphi-Quellcode:
uses JwaWinCrypt;
function CryptRDPPassword(sPassword:
string):
string;
var DataIn: DATA_BLOB;
DataOut: DATA_BLOB;
pwDescription: PWideChar;
P: PByte;
I: Integer;
PwdHash:
string;
begin
PwdHash := '
';
DataOut.cbData := 0;
DataOut.pbData :=
nil;
// RDP uses UniCode
DataIn.pbData := Pointer(WideString(sPassword));
DataIn.cbData := Length(sPassword) * SizeOf(WChar);
// RDP always sets description to psw
pwDescription := WideString('
psw');
if CryptProtectData(@DataIn,
pwDescription,
nil,
nil,
nil,
CRYPTPROTECT_UI_FORBIDDEN,
// Never show interface
@DataOut)
then
begin
// Convert the DataBlob to Hex String
P := DataOut.pbData;
I := DataOut.cbData;
PwdHash := '
';
while (I > 0)
do begin
Dec(I);
PwdHash := PwdHash + IntToHex(P^, 2);
Inc(P);
end;
end;
Result := PwdHash;
// Cleanup
pwDescription :=
nil;
LocalFree(Cardinal(DataOut.pbData));
LocalFree(Cardinal(DataIn.pbData));
end;