gpt4 book ai didi

Python3 Cryptodome - 如何解密pem?

转载 作者:行者123 更新时间:2023-12-01 08:50:14 24 4
gpt4 key购买 nike

我正在尝试使用 cryptodome 在 python 中解密我的私钥。 raw_cipher_data下是我加密私钥的密码。但我收到错误消息“ValueError:PEM 已加密,但没有可用的密码”

我的导入

from Cryptodome.Signature import PKCS1_v1_5
from Cryptodome.Hash import SHA
from Cryptodome.PublicKey import RSA
from base64 import b64decode

代码

rsa_key = RSA.importKey(open('pem file location', "rb").read())
verifier = PKCS1_v1_5.new(rsa_key)
raw_cipher_data = b64decode(<your cipher data>)
phn = rsa_key.decrypt(raw_cipher_data)

我的错误信息

  File ".\app.py", line 24, in <module>
rsa_key = RSA.importKey(f.read(), passphrase="CNt3wiSY3Sjn0fEh2fsq")
File "C:\Users\xx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\Cryptodome\PublicKey\RSA.py", line 733, in import_key
(der, marker, enc_flag) = PEM.decode(tostr(extern_key), passphrase)
File "C:\Users\xx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\Cryptodome\IO\PEM.py", line 163, in decode
data = unpad(objdec.decrypt(data), objdec.block_size)
File "C:\Users\xx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\Cryptodome\Util\Padding.py", line 90, in unpad
raise ValueError("Padding is incorrect.")
ValueError: Padding is incorrect.

最佳答案

我认为您的 RSA key 已加密。根据文档,您应该提供这样的密码
rsa_key = RSA.importKey(open('pem 文件位置', "rb").read(), passphrase="yourpasswordhere")

关于Python3 Cryptodome - 如何解密pem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53155468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com