Created
January 9, 2024 10:52
-
-
Save Alex4386/49fbc41570bf743e870c7dce7f1f2d60 to your computer and use it in GitHub Desktop.
convert certbot to asn1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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