Exemplo n.º 1
0
def test_pkcs7_pad_invalid_block_size():
    with pytest.raises(ValueError):
        set2.pkcs7_pad(b"YELLOW SUBMARINE", 0)
    with pytest.raises(ValueError):
        set2.pkcs7_pad(b"YELLOW SUBMARINE", -5)
    with pytest.raises(ValueError):
        set2.pkcs7_pad(b"YELLOW SUBMARINE", 14.3)
Exemplo n.º 2
0
def encrypt_user_data(plaintext, key, iv):
    return encrypt_aes_128_cbc(iv, pkcs7_pad(plaintext, block_size), key)
Exemplo n.º 3
0
def test_pkcs7_pad():
    assert set2.pkcs7_pad(b"YELLOW SUBMARINE", 20) == b"YELLOW SUBMARINE\x04\x04\x04\x04", \
        "Should have four bytes of padding"
Exemplo n.º 4
0
def test_pkcs7_pad_max_padding():
    assert set2.pkcs7_pad(b"YELLOW SUBMARINES", 16) == \
           b"YELLOW SUBMARINES\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f", \
           "Should have 15 bytes of padding"
Exemplo n.º 5
0
def test_pkcs7_pad_no_padding():
    assert set2.pkcs7_pad(b"YELLOW SUBMARINE", 16) == b"YELLOW SUBMARINE", \
        "Should have no padding because input is same length as block"
Exemplo n.º 6
0
def test_challenge9():
    assert set2.pkcs7_pad(b"YELLOW SUBMARINE", 20) == b"YELLOW SUBMARINE\x04\x04\x04\x04"
    for i in range(100):
        bytestring = os.urandom(i)
        assert bytestring == set2.pkcs7_unpad(set2.pkcs7_pad(bytestring, 16), 16)
Exemplo n.º 7
0
def generate_payload_second_step():
    payload = ""
    payload += "A" * (block_size - len("email="))
    payload += pkcs7_pad(b"admin", block_size).decode()
    return payload
Exemplo n.º 8
0
def encrypt_encoded_user_cookie(user):
    return encrypt_aes_128_ecb(
        pkcs7_pad(user.encode_as_cookie().encode(), block_size),
        global_aes_128_key)