高级加密标准(aes)numpy实现
npaes的Python项目详细描述
不良资产
高级加密标准(AES)numpy实现。
警告:不完整&尚不适合生产使用。请参阅下面的“注意”部分。
Supports | Python 2.7 | 3.5 | 3.6 | 3.7 |
Latest Release | |
Package Status | |
License |
这个包实现了联邦信息处理标准出版物197(“fips197”)中指定的高级加密标准(aes):
此实现完全且仅基于fips197。tests/test_npaes.py
中的测试使用fips197附录a、b和c中的全套示例向量。npaes
支持aes-128、aes-192和aes-256。
它唯一的依赖是numpy。除了在c中实现的numpy部分之外,它不使用openssl或任何其他c库。
其他技术说明可在npaes/__init__.py
的docstring中找到。
小心
这个包裹不完整。虽然使用fips197示例向量对原始加密和解密进行了全面测试,但由于以下原因,原始加密和解密是不完整的:
- 它不允许您指定initialization vector(iv)。
- 它不允许您指定block mode。
- 它在大多数地方都进行了优化,但并不是全部,而且几乎没有机会像openssl中优化的ansi c版本那样快。
基本用法
importosfromnpaesimportAES# Key must be bytes type and 128, 192, or 256 bits# Or use hashlib.sha256() for an off-length keykey=os.urandom(32)# 256-bit key# Your plaintext length must be bytes and a multiple of 16 lengthmsg=b"a secret message goes here"+6*b"\x03"cipher=AES(key)ciphertext=cipher.encrypt(msg)print(ciphertext)# b'a\x85cna\xc2\xeeu\xe9S\xdf\xabE\x0c\xda\xf4\x19\x11\xa3!\xdd\x96-\x85\x10f\xd4\x18;s%\x81'print(cipher.decrypt(ciphertext))# b'a secret message goes here\x03\x03\x03\x03\x03\x03'