python之gmssl sm4加解密(ECB)
Python 加解密
2023-09-14 09:07:03 时间
from gmssl import sm3,sm4
def sm4_encrypt_or_decrypt(mode, key, data):
if mode == 'encrypt':
cryptor = sm4.CryptSM4(sm4.SM4_ENCRYPT,padding_mode=2)
cryptor.set_key(key, sm4.SM4_ENCRYPT)
elif mode == 'decrypt':
cryptor = sm4.CryptSM4(sm4.SM4_DECRYPT,padding_mode=2)
cryptor.set_key(key, sm4.SM4_DECRYPT)
else:
raise ValueError('Unsupported mode:', mode)
res=cryptor.crypt_ecb(data)
print(res.hex())
return res
sm4_encrypt_or_decrypt("encrypt",b"1111111111111111",b"1111111111111111")
sm4_encrypt_or_decrypt("decrypt",b"1111111111111111",b"1111111111111111")
相关文章
- python解析curl命令内容
- python小技巧
- 【学习总结】Python-3-转义字符
- Python 刷Leetcode题库,顺带学英语单词(21)
- 【OpenCV-Python】教程:7-4 KMeans 应用
- 华为OD机试 - 冠亚军排名,奖牌榜排名(Java & JS & Python)
- 现在转行学python,前景和优势有哪些?
- GitHub热榜|5款优质的Python小工具,最后一款是福利!
- Python 多线程进程高级指南(二)
- python并发模块之concurrent.futures(二)
- 【华为OD机试Python实现】HJ3 明明的随机数(较难)
- 【华为机试真题 Python实现】数大雁【2022 Q2 | 100分】
- python aes-ecb加解密
- python aes-cbc加解密
- Python: 列表推导式--轻量级循环
- python 继承
- (20)Blender源码分析之闪屏窗口的菜单python代码draw的属性和函数对应