LoginSignup
0
0

More than 1 year has passed since last update.

pythonのchacha20poly1305で暗号化

Last updated at Posted at 2021-11-09

pip install chacha20poly1305
とした後、


import os
from chacha20poly1305 import ChaCha20Poly1305

key = os.urandom(32)
cip = ChaCha20Poly1305(key)

nonce = os.urandom(12)
ciphertext = cip.encrypt(nonce, b'test')
print(ciphertext.hex())
plaintext = cip.decrypt(nonce, ciphertext)
print(plaintext)

今はやりのAEADってやつですね。
TLS1.3にも使われてます。
AEADっていう割には暗号化するときパスワードとか聞かれないので、
何を認証してるのか原理を知らないと安心して使えないですね。
MACを生成してるようなのでメッセージの改ざん検出でしょうか。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0