Python Cryptodome.Cipher.AES.MODE_CFB Examples
The following are 30
code examples of Cryptodome.Cipher.AES.MODE_CFB().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
Cryptodome.Cipher.AES
, or try the search function
.
Example #1
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 6 votes |
def test_aes_256_cfb128(self): plaintext = '6bc1bee22e409f96e93d7e117393172a' +\ 'ae2d8a571e03ac9c9eb76fac45af8e51' +\ '30c81c46a35ce411e5fbc1191a0a52ef' +\ 'f69f2445df4f9b17ad2b417be66c3710' ciphertext = 'dc7e84bfda79164b7ecd8486985d3860' +\ '39ffed143b28b1c832113c6331e5407b' +\ 'df10132415e54b92a13ed0a8267ae2f9' +\ '75a385741ab9cef82031623d55b1e471' key = '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #2
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 6 votes |
def test_aes_192_cfb128(self): plaintext = '6bc1bee22e409f96e93d7e117393172a' +\ 'ae2d8a571e03ac9c9eb76fac45af8e51' +\ '30c81c46a35ce411e5fbc1191a0a52ef' +\ 'f69f2445df4f9b17ad2b417be66c3710' ciphertext = 'cdc80d6fddf18cab34c25909c99a4174' +\ '67ce7f7f81173621961a2b70171d3d7a' +\ '2e1e8a1dd59b88b1c8e60fed1efac4c9' +\ 'c05f9f9ca9834fa042ae8fba584b09ff' key = '8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #3
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 6 votes |
def test_aes_128_cfb128(self): plaintext = '6bc1bee22e409f96e93d7e117393172a' +\ 'ae2d8a571e03ac9c9eb76fac45af8e51' +\ '30c81c46a35ce411e5fbc1191a0a52ef' +\ 'f69f2445df4f9b17ad2b417be66c3710' ciphertext = '3b3fd92eb72dad20333449f8e83cfb4a' +\ 'c8a64537a0b3a93fcde3cdad9f1ce58b' +\ '26751f67a3cbb140b1808cf187a4f4df' +\ 'c04b05357c5d1c0eeac4c66f9ff7f2e6' key = '2b7e151628aed2a6abf7158809cf4f3c' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #4
Source File: test_CFB.py From jarvis with GNU General Public License v2.0 | 6 votes |
def test_aes_256_cfb128(self): plaintext = '6bc1bee22e409f96e93d7e117393172a' +\ 'ae2d8a571e03ac9c9eb76fac45af8e51' +\ '30c81c46a35ce411e5fbc1191a0a52ef' +\ 'f69f2445df4f9b17ad2b417be66c3710' ciphertext = 'dc7e84bfda79164b7ecd8486985d3860' +\ '39ffed143b28b1c832113c6331e5407b' +\ 'df10132415e54b92a13ed0a8267ae2f9' +\ '75a385741ab9cef82031623d55b1e471' key = '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #5
Source File: test_CFB.py From jarvis with GNU General Public License v2.0 | 6 votes |
def test_aes_128_cfb128(self): plaintext = '6bc1bee22e409f96e93d7e117393172a' +\ 'ae2d8a571e03ac9c9eb76fac45af8e51' +\ '30c81c46a35ce411e5fbc1191a0a52ef' +\ 'f69f2445df4f9b17ad2b417be66c3710' ciphertext = '3b3fd92eb72dad20333449f8e83cfb4a' +\ 'c8a64537a0b3a93fcde3cdad9f1ce58b' +\ '26751f67a3cbb140b1808cf187a4f4df' +\ 'c04b05357c5d1c0eeac4c66f9ff7f2e6' key = '2b7e151628aed2a6abf7158809cf4f3c' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #6
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 6 votes |
def test_aes_128_cfb128(self): plaintext = '6bc1bee22e409f96e93d7e117393172a' +\ 'ae2d8a571e03ac9c9eb76fac45af8e51' +\ '30c81c46a35ce411e5fbc1191a0a52ef' +\ 'f69f2445df4f9b17ad2b417be66c3710' ciphertext = '3b3fd92eb72dad20333449f8e83cfb4a' +\ 'c8a64537a0b3a93fcde3cdad9f1ce58b' +\ '26751f67a3cbb140b1808cf187a4f4df' +\ 'c04b05357c5d1c0eeac4c66f9ff7f2e6' key = '2b7e151628aed2a6abf7158809cf4f3c' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #7
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 6 votes |
def test_aes_256_cfb128(self): plaintext = '6bc1bee22e409f96e93d7e117393172a' +\ 'ae2d8a571e03ac9c9eb76fac45af8e51' +\ '30c81c46a35ce411e5fbc1191a0a52ef' +\ 'f69f2445df4f9b17ad2b417be66c3710' ciphertext = 'dc7e84bfda79164b7ecd8486985d3860' +\ '39ffed143b28b1c832113c6331e5407b' +\ 'df10132415e54b92a13ed0a8267ae2f9' +\ '75a385741ab9cef82031623d55b1e471' key = '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #8
Source File: test_OFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_unaligned_data_64(self): plaintexts = [ b("7777777") ] * 100 cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=8) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=8) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts))) cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=64) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=64) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts)))
Example #9
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_segment_size_64(self): for bits in xrange(8, 65, 8): cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=bits) for bits in 0, 7, 9, 63, 65: self.assertRaises(ValueError, DES3.new, self.key_192, AES.MODE_CFB, self.iv_64, segment_size=bits)
Example #10
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def _do_kat_aes_test(self, file_name, segment_size): test_vectors = load_tests(("Cryptodome", "SelfTest", "Cipher", "test_vectors", "AES"), file_name, "AES CFB%d KAT" % segment_size, { "count" : lambda x: int(x) } ) assert(test_vectors) direction = None for tv in test_vectors: # The test vector file contains some directive lines if isinstance(tv, basestring): direction = tv continue self.description = tv.desc cipher = AES.new(tv.key, AES.MODE_CFB, tv.iv, segment_size=segment_size) if direction == "[ENCRYPT]": self.assertEqual(cipher.encrypt(tv.plaintext), tv.ciphertext) elif direction == "[DECRYPT]": self.assertEqual(cipher.decrypt(tv.ciphertext), tv.plaintext) else: assert False # See Section 6.4.5 in AESAVS
Example #11
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def _do_tdes_test(self, file_name, segment_size): test_vectors = load_tests(("Cryptodome", "SelfTest", "Cipher", "test_vectors", "TDES"), file_name, "AES CFB%d KAT" % segment_size, { "count" : lambda x: int(x) } ) assert(test_vectors) direction = None for tv in test_vectors: # The test vector file contains some directive lines if isinstance(tv, basestring): direction = tv continue self.description = tv.desc if hasattr(tv, "keys"): cipher = DES.new(tv.keys, DES.MODE_CFB, tv.iv, segment_size=segment_size) else: if tv.key1 != tv.key3: key = tv.key1 + tv.key2 + tv.key3 # Option 3 else: key = tv.key1 + tv.key2 # Option 2 cipher = DES3.new(key, DES3.MODE_CFB, tv.iv, segment_size=segment_size) if direction == "[ENCRYPT]": self.assertEqual(cipher.encrypt(tv.plaintext), tv.ciphertext) elif direction == "[DECRYPT]": self.assertEqual(cipher.decrypt(tv.ciphertext), tv.plaintext) else: assert False # Create one test method per file
Example #12
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_aes_128_cfb8(self): plaintext = '6bc1bee22e409f96e93d7e117393172aae2d' ciphertext = '3b79424c9c0dd436bace9e0ed4586a4f32b9' key = '2b7e151628aed2a6abf7158809cf4f3c' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #13
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_aes_192_cfb8(self): plaintext = '6bc1bee22e409f96e93d7e117393172aae2d' ciphertext = 'cda2521ef0a905ca44cd057cbf0d47a0678a' key = '8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #14
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_aes_256_cfb8(self): plaintext = '6bc1bee22e409f96e93d7e117393172aae2d' ciphertext = 'dc1f1a8520a64db55fcc8ac554844e889700' key = '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #15
Source File: test_OFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_unaligned_data_128(self): plaintexts = [ b("7777777") ] * 100 cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=8) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=8) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts))) cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=128) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=128) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts)))
Example #16
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_unaligned_data_64(self): plaintexts = [ b("7777777") ] * 100 cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=8) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=8) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts))) cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=64) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=64) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts))) # Extra
Example #17
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_unaligned_data_128(self): plaintexts = [ b("7777777") ] * 100 cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=8) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=8) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts))) cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=128) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=128) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts)))
Example #18
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_unaligned_data_64(self): plaintexts = [ b("7777777") ] * 100 cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=8) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=8) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts))) cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=64) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=64) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts))) # Extra
Example #19
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_segment_size_64(self): for bits in xrange(8, 65, 8): cipher = DES3.new(self.key_192, DES3.MODE_CFB, self.iv_64, segment_size=bits) for bits in 0, 7, 9, 63, 65: self.assertRaises(ValueError, DES3.new, self.key_192, AES.MODE_CFB, self.iv_64, segment_size=bits)
Example #20
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def _do_kat_aes_test(self, file_name, segment_size): test_vectors = load_tests(("Cryptodome", "SelfTest", "Cipher", "test_vectors", "AES"), file_name, "AES CFB%d KAT" % segment_size, { "count" : lambda x: int(x) } ) assert(test_vectors) direction = None for tv in test_vectors: # The test vector file contains some directive lines if isinstance(tv, basestring): direction = tv continue self.description = tv.desc cipher = AES.new(tv.key, AES.MODE_CFB, tv.iv, segment_size=segment_size) if direction == "[ENCRYPT]": self.assertEqual(cipher.encrypt(tv.plaintext), tv.ciphertext) elif direction == "[DECRYPT]": self.assertEqual(cipher.decrypt(tv.ciphertext), tv.plaintext) else: assert False # See Section 6.4.5 in AESAVS
Example #21
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def _do_tdes_test(self, file_name, segment_size): test_vectors = load_tests(("Cryptodome", "SelfTest", "Cipher", "test_vectors", "TDES"), file_name, "AES CFB%d KAT" % segment_size, { "count" : lambda x: int(x) } ) assert(test_vectors) direction = None for tv in test_vectors: # The test vector file contains some directive lines if isinstance(tv, basestring): direction = tv continue self.description = tv.desc if hasattr(tv, "keys"): cipher = DES.new(tv.keys, DES.MODE_CFB, tv.iv, segment_size=segment_size) else: if tv.key1 != tv.key3: key = tv.key1 + tv.key2 + tv.key3 # Option 3 else: key = tv.key1 + tv.key2 # Option 2 cipher = DES3.new(key, DES3.MODE_CFB, tv.iv, segment_size=segment_size) if direction == "[ENCRYPT]": self.assertEqual(cipher.encrypt(tv.plaintext), tv.ciphertext) elif direction == "[DECRYPT]": self.assertEqual(cipher.decrypt(tv.ciphertext), tv.plaintext) else: assert False # Create one test method per file
Example #22
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_aes_128_cfb8(self): plaintext = '6bc1bee22e409f96e93d7e117393172aae2d' ciphertext = '3b79424c9c0dd436bace9e0ed4586a4f32b9' key = '2b7e151628aed2a6abf7158809cf4f3c' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #23
Source File: test_CFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_aes_256_cfb8(self): plaintext = '6bc1bee22e409f96e93d7e117393172aae2d' ciphertext = 'dc1f1a8520a64db55fcc8ac554844e889700' key = '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4' iv = '000102030405060708090a0b0c0d0e0f' key = unhexlify(key) iv = unhexlify(iv) plaintext = unhexlify(plaintext) ciphertext = unhexlify(ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8) self.assertEqual(cipher.encrypt(plaintext), ciphertext) cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8) self.assertEqual(cipher.decrypt(ciphertext), plaintext)
Example #24
Source File: test_OFB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_unaligned_data_128(self): plaintexts = [ b("7777777") ] * 100 cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=8) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=8) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts))) cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=128) ciphertexts = [ cipher.encrypt(x) for x in plaintexts ] cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=128) self.assertEqual(b("").join(ciphertexts), cipher.encrypt(b("").join(plaintexts)))
Example #25
Source File: test_CFB.py From jarvis with GNU General Public License v2.0 | 5 votes |
def test_segment_size_128(self): for bits in range(8, 129, 8): cipher = AES.new(self.key_128, AES.MODE_CFB, self.iv_128, segment_size=bits) for bits in 0, 7, 9, 127, 129: self.assertRaises(ValueError, AES.new, self.key_128, AES.MODE_CFB, self.iv_128, segment_size=bits)
Example #26
Source File: pycryptodome.py From flake8-bandit with MIT License | 5 votes |
def test_pycrypto(): key = b'Sixteen byte key' iv = Random.new().read(AES.block_size) cipher = pycrypto_arc2.new(key, AES.MODE_CFB, iv) factory = CryptoMaterialsCacheEntry()
Example #27
Source File: crypto.py From fabric-sdk-py with Apache License 2.0 | 5 votes |
def encrypt(self, public_key, plain_text): """ECIES encrypt plain text. First create a ephemeral ecdsa key pair, then serialize the public key for part of result. Then derived a shared key based ecdh, using the key based hkdf to generate aes key and hmac key, using aes-256-cfb to generate the part of result. Last using hmac-sha3 and the part of previous step to generate last part of result. :param public_key: public key :param plain_text: plain text :return: cipher text """ ephemeral_private_key = self.generate_private_key() rb = ephemeral_private_key.public_key().public_bytes( serialization.Encoding.X962, serialization.PublicFormat.UncompressedPoint ) z = ephemeral_private_key.exchange(ec.ECDH(), public_key) hkdf_output = Hkdf(salt=None, input_key_material=z, hash=self._hash) \ .expand(length=AES_KEY_LENGTH + HMAC_KEY_LENGTH) aes_key = hkdf_output[:AES_KEY_LENGTH] hmac_key = hkdf_output[AES_KEY_LENGTH:AES_KEY_LENGTH + HMAC_KEY_LENGTH] aes_cipher = AES.new(aes_key, AES.MODE_CFB) em = aes_cipher.iv + aes_cipher.encrypt(plain_text) mac = hmac.new(hmac_key, em, self._hash) d = mac.digest() return rb + em + d
Example #28
Source File: nrpc.py From Slackor with GNU General Public License v3.0 | 5 votes |
def ComputeNetlogonCredentialAES(inputData, Sk): IV='\x00'*16 Crypt1 = AES.new(Sk, AES.MODE_CFB, IV) return Crypt1.encrypt(inputData) # Section 3.1.4.3.1
Example #29
Source File: nrpc.py From Slackor with GNU General Public License v3.0 | 5 votes |
def encryptSequenceNumberAES(sequenceNum, checkSum, sessionKey): # [MS-NRPC] Section 3.3.4.2.1, point 9 IV = checkSum[:8] + checkSum[:8] Cipher = AES.new(sessionKey, AES.MODE_CFB, IV) return Cipher.encrypt(sequenceNum)
Example #30
Source File: nrpc.py From Slackor with GNU General Public License v3.0 | 5 votes |
def decryptSequenceNumberAES(sequenceNum, checkSum, sessionKey): # [MS-NRPC] Section 3.3.4.2.1, point 9 IV = checkSum[:8] + checkSum[:8] Cipher = AES.new(sessionKey, AES.MODE_CFB, IV) return Cipher.decrypt(sequenceNum)