xct's notes
Search…
Misc

Parse PEM

1
#!/usr/bin/env sage
2
3
from Crypto.PublicKey import RSA
4
from Crypto.Util.number import long_to_bytes
5
6
key = RSA.importKey(open("key.pem").read())
7
print(f"d= {key.d}") # example for d
Copied!

Parse DER

1
#!/usr/bin/env sage
2
3
from asn1crypto.x509 import Certificate
4
5
with open("cert.der", "rb") as f:
6
cert = Certificate.load(f.read())
7
8
print(cert.public_key.native["public_key"]["modulus"])
9
print(cert.public_key.native["public_key"]["public_exponent"])
Copied!
Last modified 8mo ago
Copy link