python - Flutter 和 python [AES] 之间的相同加密
问题描述
我想要一些python和flutter之间加密的例子来加密客户端和服务器之间的请求和响应主体
我找到了一些用于 AES CRT 加密的示例代码,但我在颤振和 python 中看不到相同的结果
有谁能够帮我 ?
更新:Flutter crypt 包没有计数器参数,但 python Crypto.Cipher 包有计数器参数
这是python的示例代码:
plaintext = '123'.encode('utf-8')
key = '12345678911234567891123456789123'.encode("utf-8")
iv = '12345'.encode('utf')
iv_int = int(binascii.hexlify(iv), 16)
ctr = Counter.new(AES.block_size * 8, initial_value=iv_int)
aes = AES.new(key, AES.MODE_CTR, counter=ctr)
ciphertext = aes.encrypt(plaintext)
print('ctr = ' + str(ctr))
print('iv = ' + str(base64.b64encode(iv)))
print('iv_int = ' + str(iv_int))
print('plaintext = ' + str(plaintext))
print('key = ' + str(base64.b64encode(key)))
print('ciphertext = ' + str(base64.b64encode(ciphertext)))
这是颤振的示例代码:
final plainText = '123';
final key = encrypt.Key.fromUtf8('12345678911234567891123456789123');
final iv = encrypt.IV.fromUtf8('12345');
final encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.ctr));
final encrypted = encrypter.encrypt(plainText, iv: iv);
final decrypted = encrypter.decrypt(encrypted, iv: iv);
print('key = ' + key.base64);
print('iv =' + iv.base64);
print('encrypted = ' + encrypted.base64);
解决方案
推荐阅读
- python - 如何从python中的主脚本退出多处理池进程中的while循环
- r - Imports 字段中的命名空间不是从:'rlang''shinydashboard' 导入的,我应该写 @importFrom rlang rlang 还是 @importFrom rlang
- flutter - Flutter - 无法识别的应用程序。请确保您信任此应用程序,然后再继续
- asp.net - 文件上传未检测到文件扩展名
- sql - 使用 generate_series() 删除行范围?
- android - 防止请求重放攻击
- date - 在嵌套的 IFS 语句中保留 Google 表格中的日期格式
- pspice - 如何解决在 ltspice 的错误日志中发现的问题?
- outlook - 加密的 MailItem 的 PR_ATTACH_FLAGS 属性在移动到另一个文件夹后为内联附件返回 5
- python - 使用行的值作为列