全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1484
推到 Plurk!
推到 Facebook!

如何改寫 string --> byte array??

尚未結案
gloria.hk
一般會員


發表:18
回覆:17
積分:7
註冊:2005-01-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-21 17:39:40 IP:210.177.xxx.xxx 未訂閱
我從 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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-07-21 19:29:29 IP:202.39.xxx.xxx 未訂閱
參考這篇看看: http://groups.google.com.tw/group/borland.public.delphi.objectpascal/browse_thread/thread/a250d63f1c88188b/10ded876c20fa306?q=string + PByte + Move + delphi&rnum=1&hl=zh-TW#10ded876c20fa306 -- hagar.
系統時間:2024-06-28 18:44:29
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!