Skip to content

Instantly share code, notes, and snippets.

@Alex4386
Created January 9, 2024 10:52
Show Gist options
  • Save Alex4386/49fbc41570bf743e870c7dce7f1f2d60 to your computer and use it in GitHub Desktop.
Save Alex4386/49fbc41570bf743e870c7dce7f1f2d60 to your computer and use it in GitHub Desktop.
convert certbot to asn1
#!/usr/bin/python3
import sys
import json
import base64
import binascii
with open(sys.argv[1]) as fp:
pkey = json.load(fp)
def enc(data):
missing_padding = 4 - len(data) % 4
if missing_padding:
data += b'=' * missing_padding
return '0x' + binascii.hexlify(base64.b64decode(data, '-_')).decode().upper()
for k, v in pkey.items():
if k == 'kty':
continue
pkey[k] = enc(v.encode())
print("asn1=SEQUENCE:private_key\n[private_key]")
print("version=INTEGER:0")
print("n=INTEGER:{}".format(pkey['n']))
print("e=INTEGER:{}".format(pkey['e']))
print("d=INTEGER:{}".format(pkey['d']))
print("p=INTEGER:{}".format(pkey['p']))
print("q=INTEGER:{}".format(pkey['q']))
print("dp=INTEGER:{}".format(pkey['dp']))
print("dq=INTEGER:{}".format(pkey['dq']))
print("qi=INTEGER:{}".format(pkey['qi']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment