This simple code take an user input and print to stdout the sha256 of the given string.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
SHA256_CTX context;
unsigned char md[SHA256_DIGEST_LENGTH];
char *input;
printf("Watta hash: ");
scanf("%m[^\n]%*c", &input);
size_t length = strlen((const char*)input);
int i;
SHA256_Init(&context);
SHA256_Update(&context, (unsigned char*)input, length);
SHA256_Final(md, &context);
for(i=0; i<SHA256_DIGEST_LENGTH; i++){
printf("%02x", md[i]);
}
printf("\n");
free(input);
return 0;
}
My question is: how to add a salt to this hash?
添加第二次调用SHA256_Update()
,其中数据是所需的盐。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.