python字符串加密/解密错误
我一直在关注这个链接,我认为这是一个错误。这是我解密加密字符串时得到的输出。我无法复制它,因此这是图像: 它应该解密到python字符串加密/解密错误,python,encryption,Python,Encryption,我一直在关注这个链接,我认为这是一个错误。这是我解密加密字符串时得到的输出。我无法复制它,因此这是图像: 它应该解密到mYs3cr3t字符串 编辑,这是我的代码: def encrypt(self,param): BLOCK_SIZE = 16 PADDING = '{' pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING EncodeAES =
mYs3cr3t代码>字符串
编辑,这是我的代码:
def encrypt(self,param):
BLOCK_SIZE = 16
PADDING = '{'
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
secret = "mynotsosecretkey"
print 'encryption key:',secret
cipher = AES.new(secret)
encoded = EncodeAES(cipher, param)
print 'Encrypted string:', encoded
return (encoded,secret)
def decryption(self,passwd):
PADDING = '{'
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
encryption,key = self.encrypt(passwd)
cipher = AES.new(key)
decoded = DecodeAES(cipher, encryption)
print decoded
至于输出,我无法复制它,因为它包含一些奇怪的字符。请在此处发布相关代码。如果你在解释器中运行这个例子(例如空闲),你也可以复制输出。你看到的应该是明文。请打印数据的python表示形式,而不是字符串本身,方法是写入print“Decrypted,不加填充:”+repr(decoded)
。另外,请为所有中间值添加这样一行:encrypt
:print“param:”+repr(param)
,print“padded param:”+repr(pad(param))
;在解密中
:打印“密文”:+repr(cipher.decrypt(passwd))
。