-
-
Save ledeuns/c8736a03320fd6dcf73eda9031969e76 to your computer and use it in GitHub Desktop.
This file contains 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/python | |
# | |
# Converted from https://gist.github.com/JonLundy/f25c99ee0770e19dc595 to Python3 | |
import sys,json,base64,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,b'-_')).upper() | |
for k,v in list(pkey.items()): | |
if k == 'kty': continue | |
pkey[k] = enc(v.encode()) | |
print("asn1=SEQUENCE:private_key\n[private_key]\nversion=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'])) |
This file contains 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
# Let's encrypt converter | |
# Create a DER encoded private key | |
openssl asn1parse -noout -out private_key.der -genconf <(python conv.py private_key.json) | |
# Convert to PEM | |
openssl rsa -in private_key.der -inform der |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment