![]() |
Problem beim Portieren eines C++ Sources nach Delphi
Hallo liebe Leute,
ich habe mal wieder ein Problem und zwar versuche ich derzeit einen C++-Code nach Delphi (7) zu übersetzen. Die fragliche C-Funktion:
Delphi-Quellcode:
#include <windows.h>
#include <wincrypt.h>
Delphi-Quellcode:
Meine konvertierung bis jetzt:
void GetHashStr(wchar_t *Password,char *HashStr)
{ HashStr[0]='\0'; HCRYPTPROV hProv = NULL; HCRYPTHASH hHash = NULL; CryptAcquireContext(&hProv, 0,0,PROV_RSA_FULL,0); // instance of hash calculation if(CryptCreateHash(hProv,CALG_SHA1, 0, 0,&hHash)){ //calculation of hash value if(CryptHashData(hHash,(unsigned char *)Password,(wcslen(Password)+1)*2,0)){ // retrieve 20 bytes of hash value DWORD dwHashLen=20; BYTE Buffer[20]; if(CryptGetHashParam(hHash,HP_HASHVAL,Buffer,&dwHashLen,0)){ CryptDestroyHash(hHash); CryptReleaseContext(hProv, 0); // creation of character string based on hash char TmpBuf[128]; unsigned char tail=0;// variable to calculate value for the last 2 bytes // convert to a character string in hexadecimal notation for(int i=0;i<20;i++){ unsigned char c = Buffer[i]; tail+=c; wsprintf(TmpBuf,"%s%2.2X",HashStr,c); strcpy(HashStr,TmpBuf); } // add the last 2 bytes wsprintf(TmpBuf,"%s%2.2X",HashStr,tail); strcpy(HashStr,TmpBuf); } } } }
Delphi-Quellcode:
Damit kann ich mir auch sehr schön Hashes generieren lassen, es scheinen jedoch nicht die Richtige zu sein.
procedure GetHashStr(password : PWidechar; var hashstr : String);
var hProv : HCRYPTPROV; hHash : HCRYPTHASH; buffer: array[0..19] of byte; dwhashlen : DWord; i : Integer; tail : Byte; begin tail := 0; CryptAcquireContext(@hProv,0,0,PROV_RSA_FULL,0); if CryptCreatehash(hProv, CALG_SHA1, 0, 0,@hHash) Then begin if CryptHashData(hHash,@password, SizeOf(password),0) Then begin //möglicherweise falsche Größe? dwHashLen := 20; If CryptGetHashParam(hHash,HP_HASHVAL,@Buffer[0],@dwHashLen,0) Then begin CryptDestroyHash(hHash); CryptReleaseContext(hProv, 0); For i := 0 To dwHashLen - 1 Do begin tail := tail + buffer[i]; hashstr := hashstr + Format('%2.2X', [buffer[i]]); end; hashstr := hashstr + Format('%2.2X', [tail]); end; end; end; end; Meine Vermutungen wo der Fehler liegen könnte habe ich kenntlich gemacht. Ein gültiger Output für:
Delphi-Quellcode:
sollte sein:
GetHashStr('q',strq);
Zitat:
Danke im Voraus CorVu5 |
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:58 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz