python-3.x - PyCrypto AES-CTR 模式得到不同的输出
问题描述
我使用 PyCrypto 加密我的数据,但为什么他们的输出不同?
from Crypto.Cipher import AES
from Crypto.Util import Counter
data = b'\x02\x01\xf2\xca\x04\x03\x02P\x02\x02\x01\x80\xd0\x0f\x80\xd0\x0f'
key = b'random 16 string'
nonce = b'string 16 rand\x00\x01'
cipher = AES.new(key, AES.MODE_CTR, counter=lambda: nonce)
data_encrypted = cipher.encrypt(data)
print(data_encrypted)
# output is: b'_M\xed(\t4\xc4\x94\x80\x83K\x94qL\x15+R'
counter = Counter.new(2 * 8, prefix=b'string 16 rand', initial_value=1)
cipher = AES.new(key, AES.MODE_CTR, counter=counter)
data_encrypted = cipher.encrypt(data)
print(data_encrypted)
# output is: b'_M\xed(\t4\xc4\x94\x80\x83K\x94qL\x15+\xce'
这两种方法都会导致内存泄漏。如何使用pycryptodome实现第一个效果
解决方案
推荐阅读
- javascript - How can I make these components navigate to another screen in react?
- flutter - 当应用程序在后台时,来自 Flutter (FCM) 的 Firebase Messaging 插件不会在 iOS 上触发 onMessage 回调
- git - Git忽略文件的某些部分
- android - 获取手动上传到 Firebase 存储的图像文件的 url
- r - 合并 r 中具有相同行名的 2 个数据帧
- gradle - 任务:compileFunctionalTestGroovy FAILED during gradle ci build
- python - Django POST 请求:获取数据
- ios - SwiftUI - 数据源为空时动态列表过滤动画飞到右侧
- rust - 有没有办法在 Rust 宏中匹配表达式的语法类型?
- r - 如何将结果添加到 R 中循环内的向量中