crypto.load_certificate / Get public key encryption

3.6k Views Asked by At

How is it possible from crypto.load_certificate to get the public key encryption ? (for example "RSA (2048 Bits").

I can get the public key easily as below :

from OpenSSL import crypto

cert = crypto.load_certificate(crypto.FILETYPE_PEM, open("certificate.crt")).read()
pubKey = cert.get_pubkey()

But I couldn't find anything in the documentation concerning the encryption. Any ideas?

Certificate

1

There are 1 best solutions below

0
On BEST ANSWER

Actually it is really simple :

from OpenSSL import crypto

cert = crypto.load_certificate(crypto.FILETYPE_PEM, open("certificate.crt")).read()
pubKey = cert.get_pubkey()
keySize = pubKey.bits()
if pubKey.type() == crypto.TYPE_RSA:
    keyType = 'RSA'
elif pubKey.type() == crypto.TYPE_DSA:
    keyType = 'DSA'
print(keyType + "-" + str(keySize))