
	                	                 
1. str 함수는 Sodium 라이브러리의 함수 중 하나로, 비밀번호 해시를 문자열로 변환하는 역할을 합니다. 이 함수는 비밀번호 해시를 64자 길이의 알파벳 대문자와 소문자, 숫자, 특수문자로 구성된 문자열로 변환합니다.
2. str 함수를 사용하여 문자열로 변환하는 방법은 다음과 같습니다.
   - `char* hashed_password = sodium_pwhash_str_to_str(hash, 32);` 라고 작성합니다.
   - 이 함수는 `hash` 변수에 저장된 비밀번호 해시를 문자열로 변환합니다.
3. str 함수를 사용하여 문자열로 변환한 후, 다시 byte array로 변환하는 방법은 다음과 같습니다.
   - `char* hashed_password = sodium_pwhash_str_to_str(hash, 32);` 라고 작성합니다.
   - `unsigned char* hashed_password_bytes = sodium_base642bin(hashed_password, strlen(hashed_password));` 라고 작성합니다.
   - 이 함수는 `hashed_password` 변수에 저장된 문자열을 byte array로 변환합니다.
예를 들어, 다음과 같이 작성할 수 있습니다.
#hostingforum.kr
c
#include 
int main() {
    unsigned char password[32];
    unsigned char salt[16];
    unsigned char hash[32];
    // 비밀번호 및 솔트 생성
    sodium_pwhash_str(password, 32, "mysecretpassword", 16, salt, 16);
    // 해시 생성
    sodium_pwhash_scryptsalsa208sha256_str(hash, 32, password, 32, salt, 16, 4096, 8, 1);
    // 해시 문자열로 변환
    char* hashed_password = sodium_pwhash_str_to_str(hash, 32);
    // 문자열을 byte array로 변환
    unsigned char* hashed_password_bytes = sodium_base642bin(hashed_password, strlen(hashed_password));
    printf("%sn", hashed_password);
    printf("%sn", hashed_password_bytes);
    return 0;
}
이 예제에서는 `sodium_pwhash_str_to_str` 함수를 사용하여 비밀번호 해시를 문자열로 변환하고, `sodium_base642bin` 함수를 사용하여 문자열을 byte array로 변환합니다.
2025-04-05 09:56