SHA-256 algorithm implementation (С/С++)
SHA-256 algorithm implementation (С/С++)
const char* str = "test";
char hash[65] = {0}; // Notice the additional null-byte
sha256_easy_hash_hex(str, strlen(str), hash);
printf("%s\n", hash);
FILE* file = fopen("test", "rb");
char buffer[1024];
size_t size;
struct sha256_buff buff;
sha256_init(&buff);
while (!feof(file)) {
// Hash file by 1kb chunks, instead of loading into RAM at once
size = fread(buffer, 1, 1024, file);
sha256_update(&buff, buffer, size);
}
char hash[65] = {0};
sha256_finalize(&buff);
sha256_read_hex(&buff, hash);
printf("%s\n", hash);
std::cout << SHA256::hashString("test") << std::endl;
SHA256 buff;
buff.update("test", 4);
std::cout << buff.hash() << std::endl;