PyOpenSSL convert certificate object to .pem file

后端 未结 1 1441
渐次进展
渐次进展 2021-01-02 21:29

I want to send a certificate from a \"certificate authority\" to a node through sockets. I have a certificate created using this example https://skippylovesmalorie.wordpress

相关标签:
1条回答
  • 2021-01-02 21:38

    This is for generating a certificate signing request, but the concept should be the same

    from OpenSSL import crypto
    
    req = crypto.X509Req()
    pkey = crypto.PKey()
    pkey.generate_key(crypto.TYPE_RSA, 2048)
    req.set_pubkey(pkey)
    req.sign(pkey, 'sha1')
    certreq = crypto.dump_certificate_request(crypto.FILETYPE_PEM, req)
    certreq = certreq.replace('-----BEGIN CERTIFICATE REQUEST-----\n', '').replace('-----END CERTIFICATE REQUEST-----\n', '')
    private_key = crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey)
    

    for a certificate you can use:

    crypto.dump_certificate(type, cert)
    
    0 讨论(0)
提交回复
热议问题