ascii(hex)/aes_ecb
来源:互联网 发布:知源中学复读 编辑:程序博客网 时间:2024/06/07 23:16
针对密钥和密文明文都是ascii(hex)形式进行aes_ecb加密和解密
import binasciifrom cryptography.hazmat.backends import default_backendfrom cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modesfrom cryptography.hazmat.primitives.padding import PKCS7# 将密钥的ascii(hex)形式转换成字符串key = binascii.unhexlify('68656c6c6f776f726c6468656c6c6f31')print('key: {}'.format(key))def aes_ecb_encrypt(text): encryptor = Cipher( algorithms.AES(key), modes.ECB(), backend=default_backend(), ).encryptor() padder = PKCS7(128).padder() cipher_text = encryptor.update(padder.update(text) + padder.finalize()) return cipher_textdef aes_ecb_decrypt(text): decryptor = Cipher( algorithms.AES(key), modes.ECB(), backend=default_backend() ).decryptor() de_text = decryptor.update(binascii.unhexlify(text)) de_text = str(de_text).replace(r'\x05', '') return de_textif __name__ == '__main__': # 加密 cipher_text = aes_ecb_encrypt(b'12345678910') print('cipher_text: {}'.format(cipher_text)) # 将密文转成ascii(hex) hex_text = binascii.hexlify(cipher_text) print('hex_text: {}'.format(hex_text)) # 将密文的ascii(hex)形式转成明文 plaintext = aes_ecb_decrypt(hex_text) print('plaintext: {}'.format(plaintext))
阅读全文
0 0
- ascii(hex)/aes_ecb
- HEX与ASCII转换
- hex to ascii
- Java ascii to hex
- ascii互换hex
- BCD,HEX,ASCII编码
- Hex与ASCII相互转换函数
- hex to anscii or non-ascii string
- Hex和ASCII相互转换函数
- 串口的Hex/AscII发送与显示
- 串口的Hex/AscII发送与显示
- Hex与ASCII相互转换函数
- 串口的Hex/AscII发送与显示
- hex码和ascii码的转换
- 串口的Hex/AscII发送与显示
- js string hex ascii 数据转换
- [MFC]用CString表示的HEX和ASCII之间转换
- ASCII字符形式的数字和HEX形式的数字
- 几种使用itext生成pdf的方式
- 无法忍受sbt构建scala的龟速,用maven构建spark应用吧
- Android缓存策略LruCahe源码解析,Lru到底是怎么算的?
- 机器学习相关资料
- eclipse怎么自动生成返回对象
- ascii(hex)/aes_ecb
- Mysql使用while循环插入数据
- string,reverse,resize
- 操作系统 读者写者问题(含有swing)
- [171124][Web前端]JavaScript BOM参考
- 如何设置域名泛解析及解决恶意泛域名解析的方法
- linux学习 进程控制编程
- Linux文件简单介绍
- 铁路警察另一面——灵宝西所第一警务区: 张千