4 from __future__
import division
, print_function
6 from binascii
import unhexlify
13 from cryptography
.hazmat
.backends
import default_backend
14 from cryptography
.hazmat
.primitives
.ciphers
import (
15 Cipher
, algorithms
, modes
,
17 def aes_encrypt(key
, iv
, data
):
18 ciph
= Cipher(algorithms
.AES(key
), modes
.CBC(iv
), default_backend())
19 enc
= ciph
.encryptor()
20 return enc
.update(data
)
25 @pytest.mark
.skipif(not rarfile
._have
_crypto
, reason
="No crypto")
26 def test_aes128_cbc():
27 data
= b
"0123456789abcdef" * 2
31 #encdata = aes_encrypt(key, iv, data)
32 encdata
= unhexlify("4b0d438b4a1b972bd4ab81cd64674dcce4b0158090fbe616f455354284d53502")
34 ctx
= rarfile
.AES_CBC_Decrypt(key
, iv
)
35 assert ctx
.decrypt(encdata
) == data
38 @pytest.mark
.skipif(not rarfile
._have
_crypto
, reason
="No crypto")
39 def test_aes256_cbc():
40 data
= b
"0123456789abcdef" * 2
44 #encdata = aes_encrypt(key, iv, data)
45 encdata
= unhexlify("24988f387592e4d95b6eaab013137a221f81b25aa7ecde0ef4f4d7a95f92c250")
47 ctx
= rarfile
.AES_CBC_Decrypt(key
, iv
)
48 assert ctx
.decrypt(encdata
) == data