예제 #1
0
def test_cek_reuse_encryption_rsaes_rsa_oaep():
    _rsa = JWE_RSA(plain, alg="RSA-OAEP", enc="A256GCM")
    jwt = _rsa.encrypt(rsa)
    dec = JWE_RSA()
    msg = dec.decrypt(jwt, rsa)

    assert msg == plain

    _rsa2 = JWE_RSA(plain, alg="RSA-OAEP", enc="A256GCM")
    jwt = _rsa2.encrypt(None, cek=dec["cek"])
    dec2 = JWE_RSA()
    msg = dec2.decrypt(jwt, None, cek=_rsa["cek"])

    assert msg == plain
예제 #2
0
def test_cek_reuse_encryption_rsaes_rsa15():
    _rsa = JWE_RSA(plain, alg="RSA1_5", enc="A128CBC-HS256")
    jwt = _rsa.encrypt(rsa)
    dec = JWE_RSA()
    msg = dec.decrypt(jwt, rsa)

    assert msg == plain

    _rsa2 = JWE_RSA(plain, alg="RSA1_5", enc="A128CBC-HS256")
    jwt = _rsa2.encrypt(None, cek=dec["cek"])
    dec2 = JWE_RSA()
    msg = dec2.decrypt(jwt, None, cek=_rsa["cek"])

    assert msg == plain
예제 #3
0
def test_cek_reuse_encryption_rsaes_rsa_oaep():

    _rsa = JWE_RSA(plain, alg="RSA-OAEP", enc="A256GCM")
    jwt = _rsa.encrypt(rsa)
    dec = JWE_RSA()
    msg = dec.decrypt(jwt, rsa)

    assert msg == plain

    _rsa2 = JWE_RSA(plain, alg="RSA-OAEP", enc="A256GCM")
    jwt = _rsa2.encrypt(None, cek=dec["cek"])
    dec2 = JWE_RSA()
    msg = dec2.decrypt(jwt, None, cek=_rsa["cek"])

    assert msg == plain
예제 #4
0
def test_cek_reuse_encryption_rsaes_rsa15():

    _rsa = JWE_RSA(plain, alg="RSA1_5", enc="A128CBC-HS256")
    jwt = _rsa.encrypt(rsa)
    dec = JWE_RSA()
    msg = dec.decrypt(jwt, rsa)

    assert msg == plain

    _rsa2 = JWE_RSA(plain, alg="RSA1_5", enc="A128CBC-HS256")
    jwt = _rsa2.encrypt(None, cek=dec["cek"])
    dec2 = JWE_RSA()
    msg = dec2.decrypt(jwt, None, cek=_rsa["cek"])

    assert msg == plain
예제 #5
0
def test_rsa_encrypt_decrypt_rsa_cbc():
    _rsa = JWE_RSA(plain, alg="RSA1_5", enc="A128CBC-HS256")
    jwt = _rsa.encrypt(rsa)
    dec = JWE_RSA()
    msg = dec.decrypt(jwt, rsa)

    assert msg == plain
예제 #6
0
def test_rsa_encrypt_decrypt_rsa_cbc():
    _rsa = JWE_RSA(plain, alg="RSA1_5", enc="A128CBC-HS256")
    jwt = _rsa.encrypt(rsa)
    dec = JWE_RSA()
    msg = dec.decrypt(jwt, rsa)

    assert msg == plain
예제 #7
0
파일: JWE.py 프로젝트: rohe/ojou_course
# Tag.

# If the instance is going to be used to encrypt the message has to be
# available at initialization.
# If you want you can give the message when initiating the class but it
# can also be done later (just-in-time).

_rsa15_jwe = JWE_RSA(msg=plain, alg="RSA1_5", enc="A128CBC-HS256")
jwt1 = _rsa15_jwe.encrypt(rsa)

print("Parts of the encrypted JWT (RSA1_5+A128CBC-HS256)")
for p in jwt1.split('.'):
    print("-", p)

# You don't have to instanciate a new JWE_RSA class when you want to do
# decryption. Using the one you already have is OK.
msg = _rsa15_jwe.decrypt(jwt1, rsa)
print()
print("After decryption (RSA 1.5+A128CBC-HS256): {}".format(msg))

print(60*'=')

# Test using other algorithms
jwt2 = JWE_RSA(plain, alg="RSA-OAEP", enc="A256GCM").encrypt(rsa)
print("Parts of the encrypted JWT (RSA-OAEP+A256GCM)")
for p in jwt2.split("."):
    print("-", p)
msg = JWE_RSA().decrypt(jwt2, rsa)
print()
print(("After decryption (RSA-OAEP+A256GCM): {}".format(msg)))
예제 #8
0
# A JWE can then be decrypted as follow:
# - create a JWE_RSA object
# - call the decrypt method passing the JWE and the key to be used for decription

rsa = RSA.generate(4096)
plain = "Now is the time for all good men to come to the aid of their country."

_rsa15_enc = JWE_RSA(plain, alg="RSA1_5", enc="A128CBC-HS256")
jwt1 = _rsa15_enc.encrypt(rsa)

print "(1)"
for p in jwt1.split('.'):
    print "-", p

_rsa15_dec = JWE_RSA()
msg = _rsa15_dec.decrypt(jwt1, rsa)
print
print msg

###############################################

_rsaoaep_enc = JWE_RSA(plain, alg="RSA-OAEP", enc="A256GCM")
jwt2 = _rsaoaep_enc.encrypt(rsa)

print "(2)"
for p in jwt2.split('.'):
    print "-", p

_rsaoaep_dec = JWE_RSA()
msg = _rsaoaep_dec.decrypt(jwt2, rsa)
print