
Sodium 라이브러리에서 crypto_pwhash_scryptsalsa208sha256_str 함수를 사용하여 비밀번호 해시를 생성할 때, salt 값을 생성하는 방법은 다음과 같습니다.
1. salt 값은 16바이트의 난수값으로 생성됩니다.
2. Sodium 라이브러리에서 crypto_random_bytes 함수를 사용하여 salt 값을 생성할 수 있습니다.
3. 사용자 입력의 비밀번호를 salt 값과 함께 crypto_pwhash_scryptsalsa208sha256_str 함수에 전달할 때, salt 값은 매개변수로 전달됩니다.
사용 예시는 다음과 같습니다.
#hostingforum.kr
c
#include
int main() {
unsigned char salt[16];
unsigned char password[] = "mysecretpassword";
unsigned char hashed_password[crypto_pwhash_scryptsalsa208sha256_str_BYTES];
if (crypto_random_bytes(salt, 16) != 0) {
printf("salt 값 생성에 실패했습니다.n");
return 1;
}
if (crypto_pwhash_scryptsalsa208sha256_str(hashed_password,
crypto_pwhash_scryptsalsa208sha256_str_BYTES,
password, strlen(password),
salt, 16,
4096, 8, 1, 31) != 0) {
printf("비밀번호 해시 생성에 실패했습니다.n");
return 1;
}
printf("생성된 비밀번호 해시: ");
for (int i = 0; i < crypto_pwhash_scryptsalsa208sha256_str_BYTES; i++) {
printf("%02x", hashed_password[i]);
}
printf("n");
return 0;
}
이 예시는 사용자 입력의 비밀번호를 salt 값과 함께 crypto_pwhash_scryptsalsa208sha256_str 함수에 전달하여 비밀번호 해시를 생성하는 방법을 보여줍니다.
2025-08-07 02:31