#!/usr/bin/env python from oic.utils.keyio import create_and_store_rsa_key_pair for name in ['pyoidc', '2nd', '3rd']: create_and_store_rsa_key_pair("keys/{}_enc".format(name), size=2048) create_and_store_rsa_key_pair("keys/{}_sig".format(name), size=2048)
def signing_key(tmpdir): filename = "key" create_and_store_rsa_key_pair(filename, str(tmpdir), 1024) return os.path.join(str(tmpdir), filename)
#!/usr/bin/env python """ Creating and reading JWKs and JWKS """ import json from oic.utils.keyio import create_and_store_rsa_key_pair from oic.utils.keyio import build_keyjar from jwkest.jwk import RSAKey from jwkest.jwk import KEYS from jwkest.jwk import keyitems2keyreps # Will create 2 files on disc # 'foo' will contain the private key # 'foo.pub' will contain the public key key = create_and_store_rsa_key_pair("foo", size=2048) rsa = RSAKey().load_key(key) # by default this will be the public part of the key ser_rsa = rsa.serialize() print("--- JWK (public) ----") print(json.dumps(ser_rsa, sort_keys=True, indent=4, separators=(',', ': '))) print() # and this will give you the serialization of the private key ser_rsa = rsa.serialize(private=True) print("--- JWK (private) ----") print(json.dumps(ser_rsa, sort_keys=True, indent=4, separators=(',', ': '))) print()
# This example will create and print both of them, it can be executed without the need to create a foo RSA key because # the library will take care of creating it. # # Now a JWK can be created as follow: # - retrieve the rsa key # - create a RSAKey object, and load the key with the load_key method # # A JWKS can instead be created as follow: # - retrieve the rsa key # - create a KEYS object and add the keys specifying the algorithm used for creation and the usage allowed for the key # (signature or encryption) # # A key jar can also be created with the method build_keyjar specifying a key_conf containing a list of keys to be # created, with their type, name and usage (encryption of signature) key = create_and_store_rsa_key_pair("foo", size=4096) key2 = create_and_store_rsa_key_pair("foo2", size=4096) rsa = RSAKey().load_key(key) print "--- JWK ---" print json.dumps(rsa.serialize(), sort_keys=True, indent=4, separators=(',', ': ')) print ######################################################## keys = KEYS() keys.wrap_add(key, use="sig", kid="rsa1") keys.wrap_add(key2, use="enc", kid="rsa1") print "--- JWKS---" print keys.dump_jwks()
#!/usr/bin/env python __author__ = 'roland' from oic.utils.keyio import create_and_store_rsa_key_pair create_and_store_rsa_key_pair('pyoidc_enc', size=2048) create_and_store_rsa_key_pair('pyoidc_sig', size=2048)