라이브러리
[PHP] sodium_crypto_auth_verify - 태그가 메시지에 유효한지 확인합니다.
Sodium_crypto_auth_verify: PHP에서 인증 메시지 검증
Sodium_crypto_auth_verify는 PHP에서 제공하는 함수로, 인증 메시지의 유효성을 검증하는 데 사용됩니다. 이 함수는 Sodium_crypto_auth 함수와 함께 사용하여, 메시지의 무결성을 보장할 수 있습니다.
Sodium_crypto_auth_verify 함수의 사용법
Sodium_crypto_auth_verify 함수는 다음과 같은 형식으로 사용됩니다.
#hostingforum.kr
php
bool sodium_crypto_auth_verify(string $key, string $message, string $auth_tag)
- `$key`: 인증 메시지에 사용된 키입니다.
- `$message`: 인증 메시지입니다.
- `$auth_tag`: 인증 태그입니다.
예제: 인증 메시지 검증
다음 예제에서는 Sodium_crypto_auth_verify 함수를 사용하여 인증 메시지의 유효성을 검증하는 방법을 보여줍니다.
#hostingforum.kr
php
// 인증 키 생성
$key = random_bytes(32);
// 인증 메시지 생성
$message = "Hello, World!";
// 인증 태그 생성
$auth_tag = sodium_crypto_auth($key, $message);
// 인증 메시지의 유효성 검증
if (sodium_crypto_auth_verify($key, $message, $auth_tag)) {
echo "인증 메시지의 유효성은 검증되었습니다.";
} else {
echo "인증 메시지의 유효성은 검증되지 않았습니다.";
}
예제: 인증 메시지의 변조
다음 예제에서는 인증 메시지의 변조를 시뮬레이션하여, Sodium_crypto_auth_verify 함수의 유효성을 검증하는 방법을 보여줍니다.
#hostingforum.kr
php
// 인증 키 생성
$key = random_bytes(32);
// 인증 메시지 생성
$message = "Hello, World!";
// 인증 태그 생성
$auth_tag = sodium_crypto_auth($key, $message);
// 인증 메시지의 변조
$message_modified = "Hello, World! (변조)";
// 인증 메시지의 유효성 검증
if (sodium_crypto_auth_verify($key, $message_modified, $auth_tag)) {
echo "인증 메시지의 유효성은 검증되었습니다.";
} else {
echo "인증 메시지의 유효성은 검증되지 않았습니다.";
}
결론
Sodium_crypto_auth_verify 함수는 PHP에서 제공하는 함수로, 인증 메시지의 유효성을 검증하는 데 사용됩니다. 이 함수는 인증 키와 인증 태그를 사용하여, 메시지의 무결성을 보장할 수 있습니다. 예제를 통해, 인증 메시지의 유효성을 검증하는 방법을 보여주었습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.