简体   繁体   English

OpenSSL 加密错误:[('PEM 例程','PEM_read_bio','无起始行')]

[英]OpenSSL crypto error: [('PEM routines', 'PEM_read_bio', 'no start line')]

I am getting the following error when trying to read a certificate:尝试读取证书时出现以下错误:

OpenSSL.crypto.Error: [('PEM routines', 'PEM_read_bio', 'no start line')]

when running OpenSSL.crypto.load_certificate(FILETYPE_PEM, filename) .运行OpenSSL.crypto.load_certificate(FILETYPE_PEM, filename) I have made some research but was not able to find an answer specific to my case.我进行了一些研究,但无法找到特定于我的案例的答案。

I tried checking if the file existed with os.path.isfile(filename) which returns True , but loading the certificate ONLY raises the error above.我尝试检查文件是否存在os.path.isfile(filename)返回True ,但加载证书只会引发上述错误。

Also, when executing on the terminal openssl X509 -in file.pem , it works like a charm.此外,在终端openssl X509 -in file.pem上执行时,它的作用就像一个魅力。

The file.pem looks like this: file.pem 看起来像这样:

-----BEGIN CERTIFICATE-----
<<sensitive data>>
-----END CERTIFICATE-----

It seems to be valid since I able to perform basic openssl operations on the terminal.这似乎是有效的,因为我能够在终端上执行基本的openssl操作。 I am running CentOS 7, if that helps.如果有帮助,我正在运行 CentOS 7。

Any ideas?有什么想法吗?

Thanks!谢谢!

According to http://www.pyopenssl.org/en/stable/api/crypto.html#OpenSSL.crypto.load_certificate , load_certificate() takes a buffer (string will do) containing the certificate, not a filename.根据http://www.pyopenssl.org/en/stable/api/crypto.html#OpenSSL.crypto.load_certificateload_certificate()需要一个包含证书的缓冲区(字符串可以),而不是文件名。

Your need to do:你需要做的:

with open(filename, "r") as my_cert_file:
    my_cert_text = my_cert_file.read()
    cert = load_certificate(FILETYPE_PEM, my_cert_text)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JupyterHub openssl自签名证书“​​错误:错误:0906D06C:PEM例程:PEM_read_bio:无起始行” - JupyterHub openssl self signed cert “Error: error:0906D06C:PEM routines:PEM_read_bio:no start line” 找不到符号:_PEM_read_bio_EC_PUBKEY针对openssl 0.9.8x或1.0.0x编译时导入M2Crypto-0.20.2 - Symbol not found: _PEM_read_bio_EC_PUBKEY Importing M2Crypto-0.20.2 when compiled against openssl 0.9.8x or 1.0.0x 没有起始行:crypto/pem/pem_lib.c:745:期望:证书请求 - no start line:crypto/pem/pem_lib.c:745:Expecting: CERTIFICATE REQUEST 使用PFX证书的Python请求将不起作用! -OpenSSL.SSL.Error:[(&#39;PEM例程&#39;]-是否需要PFX到PEM的转换? - Python Requests using PFX certificate wont work ! - OpenSSL.SSL.Error: [('PEM routines'] - PFX to PEM conversion necessary? 尝试使用OpenSSL在python中读取CRL pem文件 - Trying to read CRL pem file in python with OpenSSL M2Crypto.EVP.EVPError:无法读取函数 pkey_read_pem 中的私钥 - M2Crypto.EVP.EVPError: Unable to read private key in function pkey_read_pem 为什么Bouncycastle的PEMReader无法读取此M2Crypto生成的PEM? - Why can't Bouncycastle's PEMReader read this M2Crypto-generated PEM? _ssl.c:351:错误:140B0009:SSL例程:SSL_CTX_use_PrivateKey_file:PEM库 - _ssl.c:351: error:140B0009:SSL routines:SSL_CTX_use_PrivateKey_file:PEM lib 如何在Python M2Crypto中使用.pem文件 - How to use .pem file with Python M2Crypto 如何正确读取 python RSA Pem 密钥? - How to read python RSA Pem key correctly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM