是否可以在不安装额外模块的情况下使用 AES 加密/解密数据?我需要从 C#
发送/接收数据,这些数据使用 System.Security.Cryptography
引用进行加密。
更新
我曾尝试使用 PyAES,但那太旧了。我更新了一些东西来让它工作,但它没有。
我也无法安装,因为它的最新版本是 3.3
而我的版本是 3.4
。
最佳答案
我正在使用 Cryptography图书馆。
Cryptography is an actively developed library that provides cryptographic recipes and primitives. It supports Python 2.6-2.7, Python 3.3+ and PyPy.
Here is an example如何使用该库:
>>> import os
>>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
>>> from cryptography.hazmat.backends import default_backend
>>> backend = default_backend()
>>> key = os.urandom(32)
>>> iv = os.urandom(16)
>>> cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend)
>>> encryptor = cipher.encryptor()
>>> ct = encryptor.update(b"a secret message") + encryptor.finalize()
>>> decryptor = cipher.decryptor()
>>> decryptor.update(ct) + decryptor.finalize()
'a secret message'
关于没有额外模块的Python AES加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25261647/