如何改寫 string --> byte array?? |
尚未結案
|
gloria.hk
一般會員 ![]() ![]() 發表:18 回覆:17 積分:7 註冊:2005-01-07 發送簡訊給我 |
我從 http://www.clevercomponents.com/articles/article024/passwordhash.asp 找到一個加密程式, 但想將傳入的astring 及傳出的 value 轉為 byte array(因為string 會導致 wrong result). 請教各大大應如何改寫呢? (藍色字原來的code)
function hash(AString: string): string; var context: HCRYPTPROV; hash: HCRYPTHASH; data: ^ShortInt; //data: PByte; hashSize, dwordSize: DWORD; begin if not CryptAcquireContext(@context, nil, nil, PROV_RSA_FULL, 0) then begin if not CryptAcquireContext(@context, nil, nil, PROV_RSA_FULL, CRYPT_NEWKEYSET) then raise Exception.CreateFmt('CryptAcquireContext error %d', [GetLastError()]); end; try if not CryptCreateHash(context, CALG_SHA, 0, 0, @hash) then raise Exception.CreateFmt('CryptCreateHash error %d', [GetLastError()]); if not CryptHashData(hash, Pointer(APassword), Length(APassword), 0) then raise Exception.CreateFmt('CryptHashData error %d', [GetLastError()]); data := nil; try dwordSize := SizeOf(DWORD); if not CryptGetHashParam(hash, HP_HASHSIZE, @hashSize, @dwordSize, 0) then raise Exception.CreateFmt('CryptGetHashParam error %d', [GetLastError()]); GetMem(data, hashSize); //if not CryptGetHashParam(hash, HP_HASHVAL, data, @hashSize, 0) then if not CryptGetHashParam(hash, HP_HASHVAL, PByte(data), @hashSize, 0) then raise Exception.CreateFmt('CryptGetHashParam error %d', [GetLastError()]); 不知如何改寫 SetLength(Result, hashSize); |
hagar
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |