我正在使用SHA256在循環中生成C中的散列值以及要生成散列的值,同時循環的計數器變量也被傳遞。由於計數器變量的值在每次迭代中都會發生變化,所以我希望SHA256每次都返回不同的散列值。但是每次都會返回相同的散列值。 請幫忙!SHA256爲每個輸入生成相同的散列值
由於提前
代碼:
int generate_sha256hash {
int loop = 0;
unsigned char hash_paramters[2] = {0};
unsigned char device_ids[2] = {0,0};
hash_paramters[0] = 0;
unsigned char pass_string = "PASSWORD";
for(loop = 1; loop < 10; loop++) {
hash_paramters[1] = loop;
memcpy((unsigned char)(&input_info[0]),(unsigned char)hash_paramters ,2);
memcpy((unsigned char)(&input_info[2]),(unsigned char)device_ids,2);
memcpy((unsigned char)(&device_info[4]),(unsigned char*)au8defaultPwd,8);
printf("\n Generating Hash Value ");
hash_value = SHA256(device_info,14,au8HashValue);
}
}
請問你可以發表一些代碼嗎?我猜你的計數器沒有更新或沒有被正確使用。 – KryptoniteDove 2012-04-23 11:42:39
感謝KryptoniteDove的迴應。我爲此添加了代碼片段。 – user1299759 2012-04-23 11:56:31
int generate_sha256hash { \t int loop = 0; \t unsigned char hash_paramters [2] = {0}; \t unsigned char device_ids [2] = {0,0}; \t hash_paramters [0] = 0; \t unsigned char * pass_string =「PASSWORD」; (循環= 1;循環<10;循環++) \t {hash_paramters [1] = loop; memcpy((unsigned char *)(&input_info [0]),(unsigned char *)hash_paramters,2); memcpy((unsigned char *)(&input_info [2]),(unsigned char *)device_ids,2); memcpy((unsigned char *)(&device_info [4]),(unsigned char *)au8defaultPwd,8); \t \t printf(「\ n Generating Hash Value」); \t \t hash_value = SHA256(device_info,14,au8HashValue); \t} } – user1299759 2012-04-23 12:01:45