没有额外模块的Python AES加密

标签 python aes python-3.4

是否可以在不安装额外模块的情况下使用 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/

相关文章:

python - Python 中的嵌套循环将结果存储在单个字典中

python - 在 Python 中比较大字符串的好方法?

python - 如何修复指出字符串无法转换为 float 的值错误

ios - iOS 中 256 block 大小的 AES 256 位加密

python - 从Python中的字符串中去除不可打印的字符?

python - 将 Python MeshGrid 拆分为单元格

c - AES 128 CBC 蒙特卡罗测试

php - 如何在 PHP 中进行 AES256 解密?

python - 如何使用 sys.path_hooks 自定义加载模块?

python-3.4 - 在不同分辨率的不同计算机上运行 Pyautogui