How to use the josepy.JWKRSA.json_loads function in josepy

To help you get started, we’ve selected a few josepy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zenhack / simp_le / simp_le.py View on Github external
def load_jwk(cls, data):
        """Load JWK."""
        return jose.JWKRSA.json_loads(data)
github aptise / peter_sslers / peter_sslers / lib / cert_utils.py View on Github external
def convert_lejson_to_pem(pkey_jsons):
    """
    This routine will use crypto/certbot if available.
    If not, openssl is used via subprocesses

    input is a json string
    much work from https://gist.github.com/JonLundy/f25c99ee0770e19dc595

    openssl asn1parse -noout -out private_key.der -genconf <(python conv.py private_key.json)
    openssl rsa -in private_key.der -inform der > private_key.pem
    openssl rsa -in private_key.pem
    """
    log.info("convert_lejson_to_pem >")

    if cryptography_serialization:
        pkey = josepy.JWKRSA.json_loads(pkey_jsons)
        as_pem = pkey.key.private_bytes(
            encoding=cryptography_serialization.Encoding.PEM,
            format=cryptography_serialization.PrivateFormat.TraditionalOpenSSL,
            encryption_algorithm=cryptography_serialization.NoEncryption(),
        )
        if six.PY3:
            as_pem = as_pem.decode()
        as_pem = cleanup_pem_text(as_pem)

        # note: we don't need to provide key_pem_filepath before we won't rely on openssl
        validate_key(key_pem=as_pem)
        return as_pem

    log.debug(".convert_lejson_to_pem > openssl fallback")
    pkey_ans1 = convert_jwk_to_ans1(pkey_jsons)
    as_pem = None