Beispiel #1
0
    def test_simple(self):
        iv = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
        plain = b"deadbeefdeadbeef"
        key = b"Yellow submarineazertyui"
        aes = AES(key, Mode.CBC, Padding.NONE, iv)
        cipher = aes.encrypt(plain)
        aestrue = pyAES.new(key, pyAES.MODE_CBC, iv)
        expected = binascii.hexlify(aestrue.encrypt(plain))
        self.assertEqual(cipher, expected.decode())
        self.assertEqual(aes.decrypt(cipher), plain)

        plain = b"Submarine yellow"
        cipher = aes.encrypt(plain)
        aestrue = pyAES.new(key, pyAES.MODE_CBC, iv)
        expected = binascii.hexlify(aestrue.encrypt(plain))
        self.assertEqual(cipher, expected.decode())
        self.assertEqual(aes.decrypt(cipher), plain)

        key = b"\x00" * 24
        plain = b"Hello world!!!!!"
        aes = AES(key, Mode.CBC, Padding.NONE, iv)
        cipher = aes.encrypt(plain)
        aestrue = pyAES.new(key, pyAES.MODE_CBC, iv)
        expected = binascii.hexlify(aestrue.encrypt(plain))
        self.assertEqual(cipher, expected.decode())
        self.assertEqual(aes.decrypt(cipher), plain)
Beispiel #2
0
 def test_pkcs(self):
     iv = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
     plain = b"deadbeef"
     key = b"Yellow submarine"
     aes = AES(key, Mode.CBC, Padding.PKCS7, iv)
     cipher = aes.encrypt(plain)
     aestrue = pyAES.new(key, pyAES.MODE_CBC, iv)
     expected = binascii.hexlify(aestrue.encrypt(plain + b"\x08" * 8))
     self.assertEqual(cipher, expected.decode())
     self.assertEqual(aes.decrypt(cipher), plain)
Beispiel #3
0
 def test_zero(self):
     iv = b"\xca" * 16
     plain = b"deadbeef"
     key = b"Yellow submarine"
     aes = AES(key, Mode.CBC, Padding.ZERO, iv)
     cipher = aes.encrypt(plain)
     aestrue = pyAES.new(key, pyAES.MODE_CBC, iv)
     expected = binascii.hexlify(aestrue.encrypt(plain + bytes(8)))
     self.assertEqual(cipher, expected.decode())
     self.assertEqual(aes.decrypt(cipher), plain)
Beispiel #4
0
def handle_aes(args):
    if args.action == "oracle":
        host = {}
        host["hostname"] = args.host
        host["port"] = args.port
        host["error"] = args.error.encode()
        return padding_oracle(args.c.encode(), host)
    if args.iv:
        args.iv = args.iv.encode()
    aes = AES(args.key.encode(), Mode[args.mode], Padding[args.padding],
              args.iv)
    if args.action == "encrypt":
        return aes.encrypt(args.m.encode())
    elif args.action == "decrypt":
        return aes.decrypt(args.c)
Beispiel #5
0
    def test_simple(self):
        plain = b"deadbeefdeadbeef"
        key = b"Yellow submarineazertyui"
        aes = AES(key, Mode.ECB, Padding.NONE)
        cipher = aes.encrypt(plain)
        aestrue = pyAES.new(key, pyAES.MODE_ECB)
        expected = binascii.hexlify(aestrue.encrypt(plain))
        self.assertEqual(cipher, expected.decode())
        self.assertEqual(aes.decrypt(cipher), plain)

        plain = b"Submarine yellow"
        cipher = aes.encrypt(plain)
        expected = binascii.hexlify(aestrue.encrypt(plain))
        self.assertEqual(cipher, expected.decode())
        self.assertEqual(aes.decrypt(cipher), plain)

        key = b"\x00" * 24
        plain = b"Hello world!!!!!"
        aes = AES(key, Mode.ECB, Padding.NONE)
        cipher = aes.encrypt(plain)
        aestrue = pyAES.new(key, pyAES.MODE_ECB)
        expected = binascii.hexlify(aestrue.encrypt(plain))
        self.assertEqual(cipher, expected.decode())
        self.assertEqual(aes.decrypt(cipher), plain)
Beispiel #6
0
    def test_multiple(self):
        key = b"\x00" * 24
        plain = b"Hello world!!!!  !!!!dlrow olleH"
        aes = AES(key, Mode.ECB, Padding.NONE)
        cipher = aes.encrypt(plain)
        aestrue = pyAES.new(key, pyAES.MODE_ECB)
        expected = binascii.hexlify(aestrue.encrypt(plain))
        self.assertEqual(cipher, expected.decode())
        self.assertEqual(aes.decrypt(cipher), plain)

        key = b"Yellow submarine01234567"
        plain = b"deadbeefdeadbeef" * 10
        aes = AES(key, Mode.ECB, Padding.NONE)
        cipher = aes.encrypt(plain)
        aestrue = pyAES.new(key, pyAES.MODE_ECB)
        expected = binascii.hexlify(aestrue.encrypt(plain))
        self.assertEqual(cipher, expected.decode())
        self.assertEqual(aes.decrypt(cipher), plain)