使用来自Crypto.Util.Padding的Unpad的ValueError

问题描述

大家好,我正在做一个有加密密码的工作(使用 DES.cbc )。我必须找到1到899998之间的正确密钥,这将给我一些帮助就像解密后的2222 3333 4444 5555,这是一个有效的锁号。

我尝试遍历1到899998,并使用 unpad 从加密文本中删除所有填充的字节,但这给了我

Set<StatuteType> statuteTypes = Optional.ofNullable(registration)
    .map(Registration_Base::getStudent)
    .map(student -> student.getStudentStatutesSet())
    .map(Collection::stream)
    .map(x -> // Optional.map
        x.map(StudentStatute_Base::getType) // Stream.map
            .filter(Objects::nonNull) // I assume you want to filter out the statute types which are null?
            .collect(Collectors.toSet())
    )
    .orElse(null);
    raise ValueError("Padding is incorrect.")
ValueError: Padding is incorrect.
from Crypto.Cipher import DES3
from Crypto.Hash import MD5
from base64 import b64encode,b64decode
from Crypto.Util.Padding import pad,unpad

def encrypt(m):
    username = '899998'
    initial_key = "J1n$h0ng#uw4" + username
    hashed = MD5.new(initial_key.encode('utf-8'))
    hash_string = hashed.digest()
    final_key = hash_string + hash_string[:8]

    initial_vector = bytes([76,144,42,58,124,103,7,117])
    des = DES3.new(final_key,DES3.MODE_CBC,initial_vector)

    # cc = bytes('2222 3333 5555 8888','utf-8')
    cc = bytes(card,'utf-8')
    padded_cc = pad(cc,8)

    msg = des.encrypt(padded_cc)
    encrypted = b64encode(msg).decode("utf-8")
    return encrypted


def decrypt(e):
    e = b64decode(e)
    for key in range(0,899998):
        initial_key = "J1n$h0ng#uw4" + str(key)
        hashed = MD5.new(initial_key.encode('utf-8'))
        hash_string = hashed.digest()
        final_key = hash_string + hash_string[:8]

        initial_vector = bytes([76,117])
        des = DES3.new(final_key,initial_vector)
        msg = unpad(des.decrypt(e),8)
        print(msg)

如果我使用899998的密钥值解密 e ,我得到2222 3333 4444 5555,我的任务是找到 a_cipher 的密钥,以便使用该密钥,我将得到上面的数字而不是十六进制转储。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)