好吧,我找到了答案,我相信它会帮助别人!
因此,“ req”证书和x509证书之间存在重要区别!
在x509中,私钥也包含在文件中!
因此,在下面,我将展示如何使用REQ和x509类型的证书生成证书并在Python中读取它.
使用“要求”证书:
生成它:
openssl req -new -newkey rsa:2048 -nodes -keyout domain.key -out domain.csr
并阅读:
import OpenSSL
# cert contains the content of domain.csr
OpenSSL.crypto.load_certificate_request(OpenSSL.crypto.FILETYPE_PEM, cert).get_subject().get_components()
使用“ x509”证书:
生成它:
openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem
并阅读:
import OpenSSL
# cert contains the content of cert.pem
OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert).get_subject().get_components()
而已 !
区别在于您如何在OpenSSL.crypto中加载证书:
>对于“要求”:load_certificate_request()
>对于“ x509”:load_certificate()
就这么简单;)