python - 在 Python 上加密 aes-256-ctr 并在 PHP 上解密
问题描述
我尝试加密数据,例如 Python 上的“qwerty”
encryption_key = Random.new().read(32)
bs = AES.block_size
iv = Random.new().read(AES.block_size)
# Convert the IV to a Python integer.
iv_int = int(binascii.hexlify(iv), 16)
countf = Counter.new(AES.block_size*8, initial_value=iv_int)
cipher = AES.new(encryption_key, AES.MODE_CTR, counter=countf)
encrypted = cipher.encrypt(data)
return b64encode(iv), b64encode(encryption_key), b64encode(encrypted)
并尝试在 PHP 上解密:
$result = openssl_decrypt(base64_decode($data['text']), "aes-256-ctr", base64_decode($data['key']), 0, base64_decode($data['iv']));
它没有用......在 $result 空字符串中。加密显然不是我的天赋:(
我需要在 python 中进行更改,以便 php 可以以这种方式解码。
解决方案
推荐阅读
- reactjs - .bind(this) 在 xhr addEventListener 中不起作用
- jasper-reports - 使用 Java Bean 数据源时交叉表数据为空?
- c++ - c++17 std::thread join() : 没有这样的过程
- javascript - Javascript + CSS 动画不起作用,可能是什么原因造成的?
- opencv - 如何“迭代”计算机视觉机器学习模型?
- r - Pivot_Longer 创建多个组合列
- flask - jinja2.exceptions.TemplateSyntaxError:遇到未知标签'url'
- python - 如何使用内部生成的输入实现 Pyaudio 回调
- c# - 循环 2 个特定列并进行计算计数器,输入另一个 datagridview
- node.js - 猫鼬 startSession() 挂起