라이브러리

[PHP] sodium_crypto_secretstream_xchacha20poly1305_rekey - secretstream 상태에서 키를 명시적으로 회전합니다.




소개


Sodium_crypto_secretstream_xchacha20poly1305_rekey는 PHP의 sodium 라이브러리에 포함된 함수로, XChaCha20-Poly1305 암호화 알고리즘을 사용하여 데이터를 암호화하고 재키를 생성하는 함수입니다. 이 함수는 데이터를 암호화하는 데 사용되는 키를 재키로 교체하는 데 사용됩니다.

사용법


Sodium_crypto_secretstream_xchacha20poly1305_rekey 함수는 다음과 같은 형식으로 사용됩니다.

#hostingforum.kr
php

string sodium_crypto_secretstream_xchacha20poly1305_rekey(string $key, string $rekey, string $aad)



- `$key`: 암호화에 사용되는 키입니다.
- `$rekey`: 새로운 키로 교체할 키입니다.
- `$aad`: 추가 인증 데이터입니다.

예제


다음 예제에서는 `sodium_crypto_secretstream_xchacha20poly1305_rekey` 함수를 사용하여 데이터를 암호화하고 재키를 생성하는 방법을 보여줍니다.

#hostingforum.kr
php

// 암호화에 사용되는 키 생성

$key = sodium_crypto_secretstream_xchacha20poly1305_key();



// 데이터를 암호화하고 재키를 생성

$stream = sodium_crypto_secretstream_xchacha20poly1305_init($key);

$sodium_crypto_secretstream_xchacha20poly1305_rekey($stream, sodium_crypto_secretstream_xchacha20poly1305_rekey_key(), "");



// 데이터를 암호화

$data = "Hello, World!";

$sodium_crypto_secretstream_xchacha20poly1305_rekey($stream, sodium_crypto_secretstream_xchacha20poly1305_rekey_key(), $data);

$encrypted_data = sodium_crypto_secretstream_xchacha20poly1305_push($stream, $data);



// 재키를 생성

$rekey = sodium_crypto_secretstream_xchacha20poly1305_rekey_key();



// 재키를 사용하여 데이터를 암호화

$sodium_crypto_secretstream_xchacha20poly1305_rekey($stream, $rekey, $data);

$encrypted_data = sodium_crypto_secretstream_xchacha20poly1305_push($stream, $data);



// 암호화된 데이터를 출력

echo $encrypted_data;



참고


- `sodium_crypto_secretstream_xchacha20poly1305_key()`: 암호화에 사용되는 키를 생성합니다.
- `sodium_crypto_secretstream_xchacha20poly1305_init()`: 데이터를 암호화하는 초기화 함수입니다.
- `sodium_crypto_secretstream_xchacha20poly1305_rekey_key()`: 새로운 키로 교체할 키를 생성합니다.
- `sodium_crypto_secretstream_xchacha20poly1305_push()`: 데이터를 암호화하는 함수입니다.
- `sodium_crypto_secretstream_xchacha20poly1305_rekey()`: 데이터를 암호화하고 재키를 생성하는 함수입니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 173 페이지

검색

게시물 검색