How can I decode a SSL certificate using python?

前端 未结 5 1900
半阙折子戏
半阙折子戏 2020-12-02 14:42

How can I decode a pem-encoded (base64) certificate with Python? For example this here from github.com:

-----BEGIN CERTIFICATE-----
MIIHKjCCBhKgAwIBAgIQDnd2i         


        
5条回答
  •  一整个雨季
    2020-12-02 14:57

    This code dumps a cert file content:

    import OpenSSL.crypto
    
    cert = OpenSSL.crypto.load_certificate(
          OpenSSL.crypto.FILETYPE_PEM,
          open('/path/to/cert/file.crt').read()
    )
    
    print OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_TEXT, cert)
    

    Give it a go.

提交回复
热议问题