
sodium_crypto_box_seal 함수는 데이터를 암호화하는 데 사용되는 함수로, 전자 서명과 암호화가 결합된 형태입니다. 이 함수는 데이터를 암호화하고, 복호화에 필요한 키를 생성하는 데 사용됩니다.
이 함수를 사용하기 위해선, 먼저 두 개의 비밀 키를 생성해야 합니다. 하나는 암호화에 사용되는 키이고, 다른 하나는 복호화에 사용되는 키입니다. 이 두 개의 키는 서로 다른 값이어야 합니다.
암호화에 필요한 키를 생성하기 위해 sodium_crypto_box_keypair 함수를 사용할 수 있습니다. 이 함수는 두 개의 비밀 키를 생성하고, 복호화에 필요한 키를 생성하는 데 사용됩니다.
복호화에 필요한 키를 생성하기 위해 sodium_crypto_box_open 함수를 사용할 수 있습니다. 이 함수는 암호화된 데이터를 복호화하고, 복호화에 필요한 키를 생성하는 데 사용됩니다.
예를 들어, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
c
#include
int main() {
unsigned char pk[crypto_box_PUBLICKEYBYTES];
unsigned char sk[crypto_box_SECRETKEYBYTES];
if (crypto_box_keypair(pk, sk) != 0) {
printf("Error generating key pairn");
return 1;
}
unsigned char message[] = "Hello, World!";
unsigned char encrypted[crypto_box_SEALBYTES + strlen((char*)message)];
if (sodium_crypto_box_seal(encrypted, message, strlen((char*)message), pk) != 0) {
printf("Error sealing messagen");
return 1;
}
unsigned char decrypted[crypto_box_SEALBYTES + strlen((char*)message)];
if (sodium_crypto_box_open(encrypted, decrypted, strlen((char*)message), sk) != 0) {
printf("Error opening sealed messagen");
return 1;
}
printf("Decrypted message: %sn", decrypted);
return 0;
}
이 코드는 두 개의 비밀 키를 생성하고, 데이터를 암호화하고, 복호화하는 데 사용됩니다.
2025-06-26 01:01