【问题标题】:How to perform blowfish decryption using pycrypto如何使用 pycrypto 执行河豚解密
【发布时间】:2019-03-26 09:24:57
【问题描述】:

您好,我正在尝试使用 pycrypto 执行 BlowFish 加密/解密

这是我的示例代码文件,在解密数据时加密效果很好

它只是打印:

 Hello 8g

而不是this

这里是 BlowFish 加密解密 的完整示例代码,不知道我需要添加什么填充,我知道 BlowFISH 有一个固定数据块大小为 8 字节,其密钥长度可以从 32 到 448 位(4 到 56 字节)不等。

from Crypto.Cipher import Blowfish
from Crypto import Random
from struct import pack
bs = Blowfish.block_size
import os


encryptedpass = "myverystrongpassword"
plaintextMessage = "Hello 8gwifi.org"

iv = os.urandom(Blowfish.block_size)
bs = Blowfish.block_size


# ENcryption
cipher = Blowfish.new(encryptedpass, Blowfish.MODE_CBC, iv)
plen = bs - divmod(len(plaintextMessage),bs)[1]
padding = [plen]*plen
padding = pack('b'*plen, *padding)
ct = iv + cipher.encrypt(plaintextMessage + padding)


#Decryption
cipher = Blowfish.new(encryptedpass, Blowfish.MODE_CBC, iv)
msg = cipher.decrypt(ct[bs:])

print msg

【问题讨论】:

    标签: python encryption pycrypto


    【解决方案1】:

    解密后您未能删除填充。您的填充是 ASCII 字符“\x08”的 8 个字节,也称为退格字符。当您打印它时,您的终端尽职尽责地“退格”并删除了前 8 个字符,即“wifi.org”。

    【讨论】:

    • 帮我修复代码,我确实用padding加密,用padding做解密
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    相关资源
    最近更新 更多