python进行aes加密 使用ecb加密模式并进行解密 然后输出加密结果和解密结果
时间: 2023-05-22 19:05:19 浏览: 153
python实现AES加密与解密
5星 · 资源好评率100%
Sure! Here's an example code snippet in Python for AES encryption using ECB mode:
```python
from Crypto.Cipher import AES
import base64
key = '0123456789abcdef'
plaintext = 'This is a plaintext message.'
padding = '{'
pad = lambda s: s + (16 - len(s) % 16) * padding
cipher = AES.new(key, AES.MODE_ECB)
message = cipher.encrypt(pad(plaintext).encode())
# Output encrypted message
print("Encrypted message: ", base64.b64encode(message))
# Now, let's decrypt the message
cipher = AES.new(key, AES.MODE_ECB)
decrypted_message = cipher.decrypt(message).decode('utf-8').rstrip(padding)
# Output decrypted message
print("Decrypted message: ", decrypted_message)
```
Please note that this is just an example, and you should always carefully consider your encryption requirements before using any encryption algorithm in production.
阅读全文