Beispiel #1
0
def test_decrypt_wrong_key():
    lib = Crypto()

    key1 = lib.generate_key()
    key2 = lib.generate_key()
    assert key1 != key2

    lib.use_encryption_key(key1)
    text = "An example string\nWith some secret content"
    token = lib.encrypt_string(text)

    lib.use_encryption_key(key2)
    with pytest.raises(ValueError):
        lib.decrypt_string(token)
Beispiel #2
0
def test_encrypt_decrypt_string():
    lib = Crypto()

    key = lib.generate_key()
    lib.use_encryption_key(key)

    text = "An example string\nWith some secret content"
    encrypted = lib.encrypt_string(text)

    assert encrypted != text
    assert base64.urlsafe_b64decode(encrypted) != text

    decrypted = lib.decrypt_string(encrypted)
    assert decrypted == text