MD5/SHA 加密處理

看來需要用這個纔是關鍵的處理。利用SHA1 源碼來處理超大文件的checksum值計算真的好慢。

 

改用:Windows Crypt API。先嚐試一下看不看快起來。

 

If you happen to be developing your code to be Microsoft Windows specific, the Windows Cryptographic Library contains the MD5 and SHA-1 hash functions. Microsoft provides functions called CryptCreateHash , CryptHashData , CryptGetHashParam and CryptDestroyHash which can be used to run the MD5 or SHA-1 hash functions on given message data to produce a message digest.

The use of these functions is pretty simple. First, as with most Windows cryptography operations, you need to create a Crypt Context using the CryptAcquireContext function. Once the context is acquired, you must create a hash object using the CryptCreateHash function. This hash object will hold the state of your hash function and will also hold the result when complete. When you call CryptCreateHash , you must specify which hash function you want. You can choose between several hash functions: CALG_MD2, CALG_MD4, CALG_MD5, CALG_SHA1, CALG_SHA_256, CALG_SHA_384 and CALG_SHA_512. Each of these cryptographic hash algorithms can have different message digest lengths.

Once the hash object is created, you must call the CryptHashData function. This function is used to pass the message data into the cryptographic hash function. This function can be called multiple times to keep feeding message data into the function. This is helpful if you are reading data from a file or other stream. Once you are done feeding data to the function, you need to retrieve the message digest from the hash object. You do this using the CryptGetHashParam function. This function will be called twice. Once for retrieving the length of the digest (HP_HASHSIZE) and again for retrieving the digest itself (HP_HASHVAL). Once you have the message digest, you can destroy the hash object and the crypt context using the CryptDestroyHash and CryptReleaseContext functions respectively.

 

 

參考:http://www.tomhandal.com/DevBlog/2010/06/13/md5sha-1-cryptographic-hash-functions-in-windows/

http://blog.csdn.net/dkfdtf/archive/2009/03/14/3989388.aspx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章