当前位置: 首页>>代码示例>>Python>>正文


Python JWE.decrypt方法代码示例

本文整理汇总了Python中jwkest.jwe.JWE.decrypt方法的典型用法代码示例。如果您正苦于以下问题:Python JWE.decrypt方法的具体用法?Python JWE.decrypt怎么用?Python JWE.decrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jwkest.jwe.JWE的用法示例。


在下文中一共展示了JWE.decrypt方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_pop_jwe

# 需要导入模块: from jwkest.jwe import JWE [as 别名]
# 或者: from jwkest.jwe.JWE import decrypt [as 别名]
def test_pop_jwe():
    jwk = {"kty": "oct", "alg": "HS256",
           "k": "ZoRSOrFzN_FzUA5XKMYoVHyzff5oRJxl-IXRtztJ6uE"}

    encryption_keys = [RSAKey(use="enc", key=rsa,
                              kid="some-key-id")]
    jwe = JWE(json.dumps(jwk), alg="RSA-OAEP", enc="A256CBC-HS512")
    _jwe = jwe.encrypt(keys=encryption_keys, kid="some-key-id")

    jwt = {
        "iss": "https://server.example.com",
        "aud": "https://client.example.org",
        "exp": 1361398824,
        "cnf": {
            "jwe": _jwe
        }
    }

    pjwt = PJWT(**jwt)

    s = pjwt.to_json()

    de_pjwt = PJWT().from_json(s)
    assert _eq(de_pjwt.keys(), ['iss', 'aud', 'exp', 'cnf'])
    assert list(de_pjwt['cnf'].keys()) == ['jwe']
    _jwe = de_pjwt['cnf']['jwe']
    msg = jwe.decrypt(_jwe, encryption_keys)
    assert msg

    assert json.loads(msg.decode('utf8')) == jwk
开发者ID:Magosgruss,项目名称:pyoidc,代码行数:32,代码来源:test_popjwt.py

示例2: test_encrypt_decrypt_rsa_cbc

# 需要导入模块: from jwkest.jwe import JWE [as 别名]
# 或者: from jwkest.jwe.JWE import decrypt [as 别名]
def test_encrypt_decrypt_rsa_cbc():
    _key = RSAKey(key=rsa)
    _key._keytype = "private"
    _jwe0 = JWE(plain, alg="RSA1_5", enc="A128CBC-HS256")

    jwt = _jwe0.encrypt([_key])

    _jwe1 = JWE()
    msg = _jwe1.decrypt(jwt, [_key])

    assert msg == plain
开发者ID:dv10den,项目名称:pyjwkest,代码行数:13,代码来源:test_2_jwe.py

示例3: deconstruct_state

# 需要导入模块: from jwkest.jwe import JWE [as 别名]
# 或者: from jwkest.jwe.JWE import decrypt [as 别名]
def deconstruct_state(relay_state, keys, alg="A128KW", enc="A128CBC-HS256"):
    """
    Deconstruct the SAML RelayState (received back from the IdP).

    :param relay_state: A JWS
    :param key: A decryption key (a SYMKey instance)
    :return: The payload of the JWS
    """
    jwe = JWE(alg=alg, enc=enc)
    payload, success = jwe.decrypt(relay_state, keys)
    if success:
        return json.loads(payload)
    else:
        raise DecryptionFailed()
开发者ID:SvHu,项目名称:svs,代码行数:16,代码来源:utils.py

示例4: test_enc_hmac

# 需要导入模块: from jwkest.jwe import JWE [as 别名]
# 或者: from jwkest.jwe.JWE import decrypt [as 别名]
def test_enc_hmac():
    payload = {'nonce': 'CYeHPyA6Kmr_jy5HDHXykznu2BpDLm8ngbIJvhBoupI,',
               'sub': 'diana', 'iss': 'https://xenosmilus2.umdc.umu.se:8091/',
               'acr': '2', 'exp': 1401176001, 'iat': 1401096801,
               'aud': ['ApB7TBoKV1tV']}

    _jwe = JWE(json.dumps(payload), alg="A128KW", enc="A128CBC-HS256")

    kb = KeyBundle(JWK1["keys"])
    kj = KeyJar()
    kj.issuer_keys["abcdefgh"] = [kb]
    keys = kj.get_encrypt_key(owner="abcdefgh")

    _enctxt = _jwe.encrypt(keys, context="public")
    assert _enctxt

    # and now for decryption

    msg, state = _jwe.decrypt(_enctxt, keys)

    assert json.loads(msg) == payload
开发者ID:dallerbarn,项目名称:pyoidc,代码行数:23,代码来源:test_keyio.py

示例5: test_pjwt_with_jwe_jwk

# 需要导入模块: from jwkest.jwe import JWE [as 别名]
# 或者: from jwkest.jwe.JWE import decrypt [as 别名]
def test_pjwt_with_jwe_jwk():
    keys = KEYS()
    keys.append(RSAKey(use="enc", key=rsa, kid="some-key-id"))

    jwe = JWE(alg="RSA-OAEP", enc="A256CBC-HS512")

    pj = PopJWT("https://server.example.com", "https://client.example.org",
                sub='12345678', jwe=jwe, keys=keys)

    jwk = {"kty": "oct", "alg": "HS256",
           "k": "ZoRSOrFzN_FzUA5XKMYoVHyzff5oRJxl-IXRtztJ6uE"}

    pjwt = pj.pack_jwe(jwk=jwk, kid='some-key-id')

    s = pjwt.to_json()

    de_pjwt = PJWT().from_json(s)
    assert _eq(de_pjwt.keys(), ['iss', 'aud', 'exp', 'cnf', 'sub', 'iat'])
    assert list(de_pjwt['cnf'].keys()) == ['jwe']
    _jwe = de_pjwt['cnf']['jwe']
    msg = jwe.decrypt(_jwe, keys.keys())
    assert msg

    assert json.loads(msg.decode('utf8')) == jwk
开发者ID:Magosgruss,项目名称:pyoidc,代码行数:26,代码来源:test_popjwt.py

示例6: from_jwe

# 需要导入模块: from jwkest.jwe import JWE [as 别名]
# 或者: from jwkest.jwe.JWE import decrypt [as 别名]
 def from_jwe(self, msg, keys):
     krs = keyitems2keyreps(keys)
     jwe = JWE()
     _res = jwe.decrypt(msg, krs)
     return self.from_json(_res[0])
开发者ID:dash-dash,项目名称:pyoidc,代码行数:7,代码来源:message.py

示例7: load_jwks_from_url

# 需要导入模块: from jwkest.jwe import JWE [as 别名]
# 或者: from jwkest.jwe.JWE import decrypt [as 别名]
    parser.add_argument("message", nargs="?", help="The message to encrypt")

    args = parser.parse_args()

    keys = {}
    if args.jwk_url:
        keys = load_jwks_from_url(args.jwk_url)
    elif args.jwk_file:
        keys = load_jwks(open(args.jwk_file).read())
    elif args.x509_url:
        keys = load_x509_cert(args.x509_url, {})
    elif args.x509_file:
        keys = [import_rsa_key_from_file(args.x509_file)]
    elif args.rsa_file:
        key = rsa_load(args.rsa_file)
        rsa_key = RSAKey(key=key)
        rsa_key.serialize()
        keys = [rsa_key]
    else:
        print("Needs encryption key")
        exit()

    if args.file:
        msg = open(args.file).read()
        msg = msg.strip("\n\r")
    else:
        msg = args.message

    jwe = JWE()
    print(jwe.decrypt(msg, keys))
开发者ID:shubhanus,项目名称:taiga,代码行数:32,代码来源:jwdecrypt.py

示例8: decrypt

# 需要导入模块: from jwkest.jwe import JWE [as 别名]
# 或者: from jwkest.jwe.JWE import decrypt [as 别名]
def decrypt(msg, keys):
    _jwe = JWE()
    return _jwe.decrypt(msg, keys)
开发者ID:juanifioren,项目名称:pyjwkest,代码行数:5,代码来源:jwkutil.py

示例9: assign

# 需要导入模块: from jwkest.jwe import JWE [as 别名]
# 或者: from jwkest.jwe.JWE import decrypt [as 别名]
        keys = assign(load_jwks(open(args.jwk_file).read()))
        if args.mode == "private":
            print >> sys.stderr, "Missing private key to decrypt with"
            exit()
    elif args.x509_url:
        keys = assign(load_x509_cert(lrequest, args.x509_url))
        if args.mode == "private":
            print >> sys.stderr, "Missing private key to decrypt with"
            exit()
    elif args.x509_file:
        keys = {"rsa": [import_rsa_key_from_file(args.x509_file)]}
        if args.mode == "private":
            print >> sys.stderr, "Missing private key to decrypt with"
            exit()
    elif args.rsa_file:
        keys = {"rsa": [rsa_load(args.rsa_file)]}
    else:
        print >> sys.stderr, "Needs encryption key"
        exit()

    if args.file:
        msg = open(args.file).read()
        msg = msg.strip("\n\r")
    else:
        msg = args.message

    krs = keyitems2keyreps(keys)

    jwe = JWE()
    print jwe.decrypt(msg, krs)
开发者ID:johanlundberg,项目名称:pyjwkest,代码行数:32,代码来源:jwdecrypt.py


注:本文中的jwkest.jwe.JWE.decrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。