|
|
@ -10,6 +10,8 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from yt_dlp.aes import (
|
|
|
|
from yt_dlp.aes import (
|
|
|
|
aes_decrypt,
|
|
|
|
aes_decrypt,
|
|
|
|
aes_encrypt,
|
|
|
|
aes_encrypt,
|
|
|
|
|
|
|
|
aes_ecb_encrypt,
|
|
|
|
|
|
|
|
aes_ecb_decrypt,
|
|
|
|
aes_cbc_decrypt,
|
|
|
|
aes_cbc_decrypt,
|
|
|
|
aes_cbc_decrypt_bytes,
|
|
|
|
aes_cbc_decrypt_bytes,
|
|
|
|
aes_cbc_encrypt,
|
|
|
|
aes_cbc_encrypt,
|
|
|
@ -17,7 +19,8 @@ from yt_dlp.aes import (
|
|
|
|
aes_ctr_encrypt,
|
|
|
|
aes_ctr_encrypt,
|
|
|
|
aes_gcm_decrypt_and_verify,
|
|
|
|
aes_gcm_decrypt_and_verify,
|
|
|
|
aes_gcm_decrypt_and_verify_bytes,
|
|
|
|
aes_gcm_decrypt_and_verify_bytes,
|
|
|
|
aes_decrypt_text
|
|
|
|
aes_decrypt_text,
|
|
|
|
|
|
|
|
BLOCK_SIZE_BYTES,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
from yt_dlp.compat import compat_pycrypto_AES
|
|
|
|
from yt_dlp.compat import compat_pycrypto_AES
|
|
|
|
from yt_dlp.utils import bytes_to_intlist, intlist_to_bytes
|
|
|
|
from yt_dlp.utils import bytes_to_intlist, intlist_to_bytes
|
|
|
@ -94,6 +97,19 @@ class TestAES(unittest.TestCase):
|
|
|
|
decrypted = (aes_decrypt_text(encrypted, password, 32))
|
|
|
|
decrypted = (aes_decrypt_text(encrypted, password, 32))
|
|
|
|
self.assertEqual(decrypted, self.secret_msg)
|
|
|
|
self.assertEqual(decrypted, self.secret_msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ecb_encrypt(self):
|
|
|
|
|
|
|
|
data = bytes_to_intlist(self.secret_msg)
|
|
|
|
|
|
|
|
data += [0x08] * (BLOCK_SIZE_BYTES - len(data) % BLOCK_SIZE_BYTES)
|
|
|
|
|
|
|
|
encrypted = intlist_to_bytes(aes_ecb_encrypt(data, self.key, self.iv))
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
|
|
|
encrypted,
|
|
|
|
|
|
|
|
b'\xaa\x86]\x81\x97>\x02\x92\x9d\x1bR[[L/u\xd3&\xd1(h\xde{\x81\x94\xba\x02\xae\xbd\xa6\xd0:')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ecb_decrypt(self):
|
|
|
|
|
|
|
|
data = bytes_to_intlist(b'\xaa\x86]\x81\x97>\x02\x92\x9d\x1bR[[L/u\xd3&\xd1(h\xde{\x81\x94\xba\x02\xae\xbd\xa6\xd0:')
|
|
|
|
|
|
|
|
decrypted = intlist_to_bytes(aes_ecb_decrypt(data, self.key, self.iv))
|
|
|
|
|
|
|
|
self.assertEqual(decrypted.rstrip(b'\x08'), self.secret_msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
unittest.main()
|
|
|
|