[python] M2Crypto를 사용하여 대칭키 복호화를 수행하는 방법은 어떻게 되나요?

우선, M2Crypto를 설치해야 합니다. 다음 명령을 사용하여 설치할 수 있습니다.

pip install M2Crypto

M2Crypto를 사용하여 대칭키를 생성하고 암호화하는 예제 코드는 아래와 같습니다.

from M2Crypto import EVP

# 대칭키 생성
key = EVP.Cipher('aes_256_cbc', 'my_secret_key', 'my_iv', 0, 1, 'md5', 1)
plaintext = 'Hello, world! This is a secret message'
ciphertext = key.update(plaintext) + key.final()

# 암호화된 텍스트 출력
print(ciphertext)

위의 코드에서 ‘my_secret_key’는 사용할 대칭키, ‘my_iv’는 초기화 벡터를 나타내며, ‘aes_256_cbc’는 암호화 알고리즘을 나타냅니다.

대칭키의 복호화는 다음과 같이 수행합니다.

# 대칭키 복호화
dec_key = EVP.Cipher('aes_256_cbc', 'my_secret_key', 'my_iv', 0, 0, 'md5', 0)
deciphertext = dec_key.update(ciphertext) + dec_key.final()

# 복호화된 텍스트 출력
print(deciphertext)

위의 예제 코드에서 ‘ciphertext’는 암호화된 텍스트를 의미합니다. ‘my_secret_key’와 ‘my_iv’는 암호화시 사용했던 값과 동일해야 합니다.

이를 참고하여 M2Crypto를 사용하여 대칭키 복호화를 수행할 수 있습니다. 더 자세한 내용은 M2Crypto 공식 문서를 참고하시기 바랍니다.