python aes new_填充不正确。AES Python加密

我正在尝试使用python构建一个简单的加密。在

这是加密:from Crypto.Cipher import AES

from Crypto.Util.Padding import pad

from Crypto.Util.Padding import unpad

BLOCK_SIZE = 32

def encrypt(message):

obj = AES.new(b'This is a key123', AES.MODE_CBC, b'This is an IV456')

return obj.encrypt(pad(message, BLOCK_SIZE))

加密似乎在返回以下内容时起作用:

^{pr2}$

但是对于解密,我使用:def decrypt(ciphertext):

obj2 = AES.new(b'This is a key123', AES.MODE_CFB, b'This is an IV456')

return obj2.decrypt(unpad(ciphertext, BLOCK_SIZE))

但它显示:Padding is incorrect

这是我要整理的整个文件:import sys

from Crypto.Cipher import AES

import importlib

try:

importlib.import_module('psutil')

except ImportError:

import pip

pip.main(['install', 'psutil'])

finally:

globals()['psutil'] = importlib.import_module('psutil')

def collect_stats():

try:

cpu = psutil.cpu_percent(interval=1)

memory = psutil.virtual_memory().percent

disk = psutil.disk_usage('/').percent

str_to_send_back = "{} {} {}".format(cpu, memory, disk)

str_to_send_back = str_to_send_back.encode()

str_to_send_back = encrypt(str_to_send_back)

except Exception as e:

print('Oops this error happened in collect_stats() inside client.py: ' + str(e))

def encrypt(message):

obj = AES.new(b'This is a key123', AES.MODE_CBC, b'This is an IV456')

return obj.encrypt(message)

def decrypt(ciphertext):

obj2 = AES.new(b'This is a key123', AES.MODE_CFB, iv)

return obj2.decrypt(ciphertext)

if __name__ == '__main__':

collect_stats()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值