Commit 4f3ae07c authored by Simo Sorce's avatar Simo Sorce Committed by Simo Sorce

Add method to import a JWK directly from json

JWK.from_json(<json_string>) will import a previously exported key.
Signed-off-by: 's avatarSimo Sorce <>

Fixes: #116
parent c527234e
......@@ -387,6 +387,19 @@ class JWK(object):
' "key_ops" values specified at'
' the same time')
def from_json(cls, key):
"""Creates a RFC 7517 JWK from the standard JSON format.
:param key: The RFC 7517 representation of a JWK.
obj = cls()
jkey = json_decode(key)
except Exception as e: # pylint: disable=broad-except
raise InvalidJWKValue(e)
return obj.import_key(**jkey)
def export(self, private_key=True):
"""Exports the key in the standard JSON format.
Exports the key regardless of type, if private_key is False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment