Exemplo n.º 1
0
def generate_service_key(service, expiration_date, kid=None, name='', metadata=None,
                         rotation_duration=None):
  private_key = RSA.generate(2048)
  jwk = RSAKey(key=private_key.publickey()).serialize()
  if kid is None:
    kid = canonical_kid(jwk)

  key = create_service_key(name, kid, service, jwk, metadata or {}, expiration_date,
                           rotation_duration=rotation_duration)
  return (private_key, key)
Exemplo n.º 2
0
def generate_key_pair(filename, kid=None):
    private_key = RSA.generate(2048)
    jwk = RSAKey(key=private_key.publickey()).serialize()
    if kid is None:
        kid = canonical_kid(jwk)

    print(("Writing public key to %s.jwk" % filename))
    with open("%s.jwk" % filename, mode="w") as f:
        f.truncate(0)
        f.write(json.dumps(jwk))

    print(("Writing key ID to %s.kid" % filename))
    with open("%s.kid" % filename, mode="w") as f:
        f.truncate(0)
        f.write(kid)

    print(("Writing private key to %s.pem" % filename))
    with open("%s.pem" % filename, mode="wb") as f:
        f.truncate(0)
        f.write(private_key.exportKey())