RSA key format is not supported
Firesuiry opened this issue · 8 comments
使用代码:
app_private_key_string ="""----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEApPbytE83VY7g2hcKyi6NKI7Fz/MyiUNkw12W/DC6W+g/NiPMgBnM0nf9k7ra34xHIMffR/Xls6gF2vWWov6dScv0YEJ+pFJJ0hoKgiv1DB1jLUKNLqr5cxIXLbL/pxvWGMiDv83evotzP+g/tXtGQt7oCf/75/qZn79oKpd4B7esZ2W8Z9sPjN1UhCfEpHRVVpm6tgXaf3ttlDjh8ghJ54nWBtOTQmkb20Ou8OlBwIINwvAyrTDSbROj8h5c21MMV84Rj6xw1fwqIkNpWIdCcAGR5XV60pPISwe1ASlHERn0WNLL+8Y82fZg7+yXv+yMOt3ni5ieKCnIi/G6mhpJOQIDAQABAoIBAD5VgghYFpSh1J0UL+OOC5DTwjN9tg7gBGc+KhtJXmH0NE6E4HVXSmoNJSh5ZtMp8oaUf+51IELurqe6PR2CEHUeOE1XUvtMjNBzPp1JduMJB7zGdQq5WGD+6Ps/tBK1FgVvXzlO1Wgy0W3ImKo+1qHWEOAWdl2F+B7A+N9/NL/VMEBaHR6RHrSE1oK93JIIiJLUy9delp2e3JZyLmuBuZBjWQ88oX3Z4k3gsJdGIAhuykr2lWepx++aPCXLGha15dlP1/dXCnf2gInYWswKFjz6BOlyNjEpyjEuKO/boG3Eg2k+jrTj7wCSGCQndD3c+byFMUYI7rau2EbvUEzy3gECgYEA1qVub1QV68V3oy0VepKGxmGY0Yn8cUgtgRlUZR4+mEZFE3v1ZjmtmcyHCKMXOaZNo/naYlnIVwd2YZIConmDTD4PlsNoMi89j7iUu7YrMcdZrREIpDpav5ZBuGVBDrcjj7BWfS1BmfsYfla28I3rC3T55RFCWOyjhIzR6x7TeGkCgYEAxL8rzQIXH9Vrc1GmlCvCsUjOeiUF/++Wbe85SciUlsWQlN1tUsLl7pA3GpTfpKDah97TkRPxmpol7L0SV74loRiRmfFzaCLTr8mQhveylnpsaZx8uHTo51jZEZgY2Fzje+D9vCSKd7yonljfZGah3SJccdekVQhGeQfaeU4BsFECgYEAjZzbfWu2grTnN6r47sNZU+z0C9rDyGFcVD5H5ebMWV6TGEXCI82N8Vh1BofDPO+xbavcHuMpP/HWco0IW/VbYKPZWRhW2DU+omGfDzEi0la5nWsNjnxJfvk9JtD22SSOu7AVf8Sp8VMuV7wSOicHmal1bWGzqkOFpl/Z5wuRbXECgYBusHstCJsH7uNX6r0EKaaMZUC9GW1Js3p3eRpK940ZUidoiTcDU+FWmU5XJyC3l0O7I1L2ETlhWI4zpZ/XO4QiIRdxe5UJJmbgRE+Kj3qrDE9ID6FfiW6rEaJ2MpLvzzqwrEE0g35fpQVcqPVtoAw6xCUsazzqFhDH8PIqQwfSMQKBgQC5ucpqYN1w1WAsXm0u0sFCf3q7ClgssU3Y2kkVshMGOSLw7xuLHcL5cCKqkNyMVocBIyA7K3odQVni7+/EU6dxUAKZRsvmlztk+qG6gjHJjhokyxLJTJu+CLQfSCagmG//YXXdndJnH4dGdaohZuNs8vlquKHd0w+noWxx3imy4Q==
-----END RSA PRIVATE KEY-----"""
app_public_key_cert_string = open('key/test/appCertPublicKey_2021000118603049.crt', 'r').read()
alipay_public_key_cert_string = open('key/test/alipayCertPublicKey_RSA2.crt', 'r').read()
alipay_root_cert_string = open('key/test/alipayRootCert.crt', 'r').read()
alipay = DCAliPay(
appid=2021000118603049,
app_notify_url="http://example.com/app_notify_url",
app_private_key_string=app_private_key_string,
app_public_key_cert_string=app_public_key_cert_string,
alipay_public_key_cert_string=alipay_public_key_cert_string,
alipay_root_cert_string=alipay_root_cert_string,
debug=True,
sign_type='RSA2',
)
报错信息:
File "D:\develop\testDjnaog\testDjnaog\urls.py", line 18, in <module>
from app import views
File "D:\develop\testDjnaog\app\views.py", line 30, in <module>
sign_type='RSA2',
File "D:\Users\46907\Anaconda3\envs\web\lib\site-packages\alipay\__init__.py", line 664, in __init__
debug=debug
File "D:\Users\46907\Anaconda3\envs\web\lib\site-packages\alipay\__init__.py", line 94, in __init__
self._load_key()
File "D:\Users\46907\Anaconda3\envs\web\lib\site-packages\alipay\__init__.py", line 99, in _load_key
self._app_private_key = RSA.importKey(content)
File "D:\Users\46907\Anaconda3\envs\web\lib\site-packages\Cryptodome\PublicKey\RSA.py", line 781, in import_key
raise ValueError("RSA key format is not supported")
ValueError: RSA key format is not supported
应用公钥crt文件:
-----BEGIN CERTIFICATE-----
MIIDmTCCAoGgAwIBAgIQICEIGTcaxQmm/XX+JXfvGjANBgkqhkiG9w0BAQsFADCBkTELMAkGA1UE
BhMCQ04xGzAZBgNVBAoMEkFudCBGaW5hbmNpYWwgdGVzdDElMCMGA1UECwwcQ2VydGlmaWNhdGlv
biBBdXRob3JpdHkgdGVzdDE+MDwGA1UEAww1QW50IEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1
dGhvcml0eSBDbGFzcyAyIFIxIHRlc3QwHhcNMjEwODE5MTQ1MjA5WhcNMjMwODE5MTQ1MjA5WjBr
MQswCQYDVQQGEwJDTjEfMB0GA1UECgwWbm1qaXNmNzMzM0BzYW5kYm94LmNvbTEPMA0GA1UECwwG
QWxpcGF5MSowKAYDVQQDDCEyMDg4NjIxOTU2Mjk5Mzg0LTIwMjEwMDAxMTg2MDMwNDkwggEiMA0G
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCNNPq0kpW/AnF5mP3hIcRw85cw/+oF+7ipABNWz8sv
hmwRdkG7PafhDmko++VWnl9e0gtHFcFeQZ2sqP9M9aw6j85rSEUm3TQJShggrGvxriCDaq2BWr5W
d9mt6Hqf4talOueSE6rksD7jf3U2K1NPb/8EV15OLav69SEfF04lcmOehXOg1YzRq00xBN5vRt3x
IYpeK34yCKjGvRFn34dnDE53GXBylUbyyG/S4myJLjoInsfyhhb/Xrx+PMLXlLK3dAMn1a6315Zu
n1z0q5IHv/WfLJ9XqgS2gZ0rI1zJG+WvCSOxI+tg4z30LKmSuyuXCevB2OqbbrtM88ZlykUXAgMB
AAGjEjAQMA4GA1UdDwEB/wQEAwIE8DANBgkqhkiG9w0BAQsFAAOCAQEAlfgmkQQ7dQJKCDZM3GC7
rKxxuxh+scJTQeF6bUnVGt+PARa7H3bDz9J9FpXQG4sXN/KebTDGPJXyWozqW8QN0PJMsCokdYNT
mnTc9R2DQWw2/Qt2Mq42MESNpHvQFrwM5U0eYP9ZLKhRXWdaaF/7KoPVirl1CIBAfoa4HglQkRxi
qdWozZu28AGvmGrkh37xJCXtD1jc6nsbADEV1UdvpjgH6jjSdgfxce//OLbevI6FpGmyk/OSZ0Vs
BnpmY7n6NCPbrKDj8GFWS15FTf1hTQqdiS+qJGpW38HXMUi+a6TAfr8Hfrd9gFCNwn48SKfYpxv8
Wt6LGJzP5OJXNB2f2w==
-----END CERTIFICATE-----
看报错信息应该是app私钥有问题 但是已经按照issue上说的加了头,但是还是不行,麻烦帮忙看下怎么回事,谢谢!
@fzlee 还有我的私钥格式和那个https://github.com/fzlee/alipay/blob/master/tests/certs/dc/app_private_key 所给出的公钥格式也不一样 请问需要提前怎么转换格式吗?
请问你的私钥是怎么生成的?
你的私钥似乎有些不对, 如果是正确的私钥 执行命令 openssl rsa -in siyue.pem -pubout 应该可以输出一些东西, 但是你的会报错。
另外你的私钥既然已经泄漏了, 可以调试完毕了换一个新的
你的私钥似乎有些不对, 如果是正确的私钥 执行命令 openssl rsa -in siyue.pem -pubout 应该可以输出一些东西, 但是你的会报错。
另外你的私钥既然已经泄漏了, 可以调试完毕了换一个新的
好的 谢谢您,我重新生成私钥下试试
你的私钥似乎有些不对, 如果是正确的私钥 执行命令 openssl rsa -in siyue.pem -pubout 应该可以输出一些东西, 但是你的会报错。
另外你的私钥既然已经泄漏了, 可以调试完毕了换一个新的
请问您生成密钥没用支付宝的工具吗?那csr文件是自己生成的吗?
可以自己生成