如何使用 openssl 解密由 pycryptodome 加密的消息

问题描述

我的加密和解密功能在这里

def enc(text):
    key = RSA.importKey(open("rsa_1024_pub.pem").read())
    cipher = PKCS1_OAEP.new(key)
    ciphertext = cipher.encrypt(bytes(aes_key,encoding = "utf8"))
    return(base64.encodebytes(ciphertext).decode())

def dec(data):
    data = base64.decodebytes(data.encode())
    key = RSA.importKey(open("rsa_1024_priv.pem").read())
    cipher = PKCS1_OAEP.new(key)
    plain_text = cipher.decrypt(data)
    return(plain_text)

当我在 python 中调用这两个函数时,效果很好

但是当我将 enc() 结果保存到一个名为 encfile 的文件并尝试使用 openssl 对其进行解密时 shell命令是这样的:

openssl rsautl -decrypt -inkey rsa_1024_priv.pem -in encfile -out decfile

我收到一条错误消息:

RSA operation error
4575256236:error:04FFF06C:rsa routines:CRYPTO_internal:data greater than mod len:/AppleInternal/buildroot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-56.60.2/libressl-2.8/crypto/rsa/rsa_eay.c:503:

然后我尝试对 encfile 进行 base64 解码并对其进行解密,出现此错误

RSA operation error
4768956076:error:04FFF06B:rsa routines:CRYPTO_internal:block type is not 02:/AppleInternal/buildroot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-56.60.2/libressl-2.8/crypto/rsa/rsa_pk1.c:185:
4768956076:error:04FFF072:rsa routines:CRYPTO_internal:padding check Failed:/AppleInternal/buildroot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-56.60.2/libressl-2.8/crypto/rsa/rsa_eay.c:580:

如何使用 openssl 解密由 pycryptodome 加密的消息?谢谢

解决方法

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

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

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