개발(합니다)/Python

[Python] cryptography로 대칭키 암호화 하는 방법

otrodevym 2021. 11. 8. 00:00
반응형

Python에서 중요한 정보를 암호화하는 방법을 cryptography를 이용하는 방법을 포스팅합니다.

cryptography 설치

pip install cryptography

python 3.7.3 이상 버전에는 기본패키지로 포함되어 있습니다.

샘플 코드

from cryptography.fernet import Fernet

key = Fernet.generate_key() # 키 임의 생성
print(key)
cipher_suite = Fernet(key)
print(cipher_suite)
cipher_text = cipher_suite.encrypt(b"hi cryptography.fernet")
plain_text = cipher_suite.decrypt(cipher_text)
print("encrypt_text : ", cipher_text)
print("decrypt_text : ", plain_text)

반응형