Created
April 14, 2020 15:09
-
-
Save redshiftzero/cd206ca16495d39a0853f83c6fcad289 to your computer and use it in GitHub Desktop.
converting armored gpg public key to JWK format - without private key
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
from authlib.common.encoding import int_to_base64 | |
import json | |
import pgpy | |
# Input is PGP armored pubkey | |
key, _ = pgpy.PGPKey.from_file('key.asc') | |
n = int(key._key.keymaterial.n) | |
e = int(key._key.keymaterial.e) | |
# Expected JWK format according to https://tools.ietf.org/html/rfc7518#section-6.1 | |
pubkey = { | |
'kty': 'RSA', | |
'e': int_to_base64(e), | |
'n': int_to_base64(n) | |
} | |
print(json.dumps(pubkey)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment