sodium_crypto_stream_xchacha20_xor_ic

(PHP 8 >= 8.2.0)

sodium_crypto_stream_xchacha20_xor_ic — nonce와 비밀 키를 사용하여 메시지를 암호화합니다(인증 없음).


설명

sodium_crypto_stream_xchacha20_xor_ic(
    string $message,
    string $nonce,
    int $counter,
    string $key
): string
                

이 함수는 sodium_crypto_stream_xchacha20_xor()와 유사하지만 블록 카운터의 초기 값을 0이 아닌 값으로 설정하는 기능을 추가합니다. 이것은 이전 블록을 계산할 필요 없이 모든 블록에 대한 직접 액세스를 허용합니다.

주의 이 암호화는 인증되지 않았으며 선택된 암호문 공격을 방지하지 않습니다. 암호문을 메시지 인증 코드와 결합해야 합니다(예: sodium_crypto_aead_xchacha20poly1305_ietf_encrypt() 함수 또는 sodium_crypto_auth()).


매개변수

message
암호화할 메시지입니다.
nonce
24-byte nonce.
counter
블록 카운터의 초기 값입니다.
key
키, 아마도 sodium_crypto_stream_xchacha20_keygen()에서 생성될 수 있습니다.

반환 값

암호화된 메시지 또는 실패 시 false입니다.


Examples

예제 #1 sodium_crypto_stream_xchacha20_xor_ic() 예제

                  
<?php
$n2 = random_bytes(SODIUM_CRYPTO_STREAM_XCHACHA20_NONCEBYTES);
$left  = str_repeat("\x01", 64);
$right = str_repeat("\xfe", 64);

// All at once:
$stream7_unified = sodium_crypto_stream_xchacha20_xor($left . $right, $n2, $key);

// Piecewise, with initial counter:
$stream7_left  = sodium_crypto_stream_xchacha20_xor_ic($left, $n2, 0, $key);
$stream7_right = sodium_crypto_stream_xchacha20_xor_ic($right, $n2, 1, $key);
$stream7_concat = $stream7_left . $stream7_right;

var_dump(strlen($stream7_concat));
var_dump($stream7_unified === $stream7_concat);
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

int(128)
bool(true)
                

기타