資源簡介
利用LibTomCrypt密碼算法庫中提供的哈希算法相關函數對一個文件進行處理,計算該文件的SHA-1值、SHA-256值和SHA-512值,提交程序代碼和運算結果;

代碼片段和文件信息
//?hash.cpp?:?定義控制臺應用程序的入口點。
//
#include?“stdafx.h“
#include?“stdlib.h“
#include
?
int?main(int?argc?_TCHAR*?argv[])
{
int?idx?err;
unsigned?long?len;
unsigned?char?out[MAXBLOCKSIZE];
/*?register?the?hash?*/
if?(register_hash(&sha1_desc)?==?-1)?{
system(“pause“);
printf(“Error?registering?sha1.\n“);
return?-1;
}
/*?get?the?index?of?the?hash?*/
idx?=?find_hash(“sha1“);
/*?call?the?hash?*/
len?=?sizeof(out);
const?unsigned?char?p[9]?=?{“11285024“};?
if?((err?=hash_memory(?idxp8out&len))?!=?CRYPT_OK)?{
printf(“Error?hashing?data:?%s\n“?error_to_string(err));
system(“pause“);
return?-1;
}
printf(“The?sha1?value?is:“);
for(int?i=0;i {
printf(“%x“out[i]);
}
printf(“\n“);
/*?register?the?hash?*/
if?(register_hash(&sha256_desc)?==?-1)?{
system(“pause“);
printf(“Error?registering?sha1.\n“);
return?-1;
}
/*?get?the?index?of?the?hash?*/
idx?=?find_hash(“sha256“);
/*?call?the?hash?*/
len?=?sizeof(out);?
if?((err?=hash_memory(?idxp8out&len))?!=?CRYPT_OK)?{
printf(“Error?hashing?data:?%s\n“?error_to_string(err));
system(“pause“);
return?-1;
}
printf(“The?sha256?value?is:“);
for(int?i=0;i {
printf(“%x“out[i]);
}
printf(“\n“);
/*?register?the?hash?*/
if?(register_hash(&sha512_desc)?==?-1)?{
system(“pause“);
printf(“Error?registering?sha1.\n“);
return?-1;
}
/*?get?the?index?of?the?hash?*/
idx?=?find_hash(“sha512“);
/*?call?the?hash?*/
len?=?sizeof(out);?
if?((err?=hash_memory(?idxp8out&len))?!=?CRYPT_OK)?{
printf(“Error?hashing?data:?%s\n“?error_to_string(err));
system(“pause“);
return?-1;
}
printf(“The?sha512?value?is:“);
for(int?i=0;i {
printf(“%x“out[i]);
}
printf(“\n“);
system(“pause“);
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1866??2013-11-29?11:20??hash\hash\hash.cpp
?????文件???????5403??2013-11-28?10:24??hash\hash\hash.vcxproj
?????文件???????2646??2013-11-28?10:24??hash\hash\hash.vcxproj.filters
?????文件????????143??2013-11-28?10:24??hash\hash\hash.vcxproj.user
?????文件???????2543??2007-05-12?22:46??hash\hash\headers\tomcrypt.h
?????文件????????977??2007-05-12?22:46??hash\hash\headers\tomcrypt_argchk.h
?????文件???????3869??2007-05-12?22:46??hash\hash\headers\tomcrypt_cfg.h
?????文件??????31702??2007-05-12?22:46??hash\hash\headers\tomcrypt_cipher.h
?????文件???????8392??2007-05-12?22:46??hash\hash\headers\tomcrypt_custom.h
?????文件??????12457??2007-05-12?22:46??hash\hash\headers\tomcrypt_hash.h
?????文件??????14482??2007-05-12?22:46??hash\hash\headers\tomcrypt_mac.h
?????文件??????14365??2007-05-12?22:46??hash\hash\headers\tomcrypt_macros.h
?????文件??????17093??2007-05-12?22:46??hash\hash\headers\tomcrypt_math.h
?????文件????????691??2007-05-12?22:46??hash\hash\headers\tomcrypt_misc.h
?????文件??????21016??2007-05-12?22:46??hash\hash\headers\tomcrypt_pk.h
?????文件???????3989??2007-05-12?22:46??hash\hash\headers\tomcrypt_pkcs.h
?????文件???????7224??2007-05-12?22:46??hash\hash\headers\tomcrypt_prng.h
?????文件????1132226??2011-11-08?10:27??hash\hash\lib_release\tomcrypt.lib
?????文件?????141570??2011-11-08?11:27??hash\hash\lib_release\tommath.lib
?????文件???????1532??2013-11-28?10:24??hash\hash\ReadMe.txt
?????文件????????209??2013-11-28?10:24??hash\hash\stdafx.cpp
?????文件????????233??2013-11-28?10:24??hash\hash\stdafx.h
?????文件????????236??2013-11-28?10:24??hash\hash\targetver.h
?????文件????3493888??2013-12-09?11:13??hash\hash.sdf
?????文件????????884??2013-11-28?13:08??hash\hash.sln
????..A..H.?????14848??2013-12-09?11:13??hash\hash.suo
?????文件????2359296??2013-12-09?11:13??hash\ipch\hash-925a3cca\hash-dc5cb190.ipch
?????目錄??????????0??2013-12-09?11:12??hash\hash\Debug
????..AD...?????????0??2013-12-09?11:11??hash\hash\headers
????..AD...?????????0??2013-12-09?11:11??hash\hash\lib_release
............此處省略8個文件信息
評論
共有 條評論