Python Cryptodome.Cipher.AES.block_size() Examples
The following are 30
code examples of Cryptodome.Cipher.AES.block_size().
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: credentials.py From plugin.video.netflix with MIT License | 6 votes |
def encrypt_credential(raw): """ Encodes data :param data: Data to be encoded :type data: str :returns: string -- Encoded data """ # pylint: disable=invalid-name,import-error import base64 try: # The crypto package depends on the library installed (see Wiki) from Crypto import Random from Crypto.Cipher import AES from Crypto.Util import Padding except ImportError: from Cryptodome import Random from Cryptodome.Cipher import AES from Cryptodome.Util import Padding raw = bytes(Padding.pad(data_to_pad=raw.encode('utf-8'), block_size=__BLOCK_SIZE__)) iv = Random.new().read(AES.block_size) cipher = AES.new(get_crypt_key(), AES.MODE_CBC, iv) return base64.b64encode(iv + cipher.encrypt(raw)).decode('utf-8')
Example #2
Source File: credentials.py From plugin.video.netflix with MIT License | 6 votes |
def decrypt_credential(enc, secret=None): """ Decodes data :param data: Data to be decoded :type data: str :returns: string -- Decoded data """ # pylint: disable=invalid-name,import-error import base64 try: # The crypto package depends on the library installed (see Wiki) from Crypto.Cipher import AES from Crypto.Util import Padding except ImportError: from Cryptodome.Cipher import AES from Cryptodome.Util import Padding enc = base64.b64decode(enc) iv = enc[:AES.block_size] cipher = AES.new(secret or get_crypt_key(), AES.MODE_CBC, iv) decoded = Padding.unpad( padded_data=cipher.decrypt(enc[AES.block_size:]), block_size=__BLOCK_SIZE__) return decoded
Example #3
Source File: test_CCM.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size(self): cipher = AES.new(self.key_128, AES.MODE_CCM, nonce=self.nonce_96) self.assertEqual(cipher.block_size, AES.block_size)
Example #4
Source File: test_CTR.py From jarvis with GNU General Public License v2.0 | 5 votes |
def test_block_size_64(self): cipher = DES3.new(self.key_192, DES3.MODE_CTR, counter=self.ctr_64) self.assertEqual(cipher.block_size, DES3.block_size)
Example #5
Source File: test_OCB.py From jarvis with GNU General Public License v2.0 | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_128, AES.MODE_OCB, nonce=self.nonce_96) self.assertEqual(cipher.block_size, AES.block_size) # By default, a 15 bytes long nonce is randomly generated nonce1 = AES.new(self.key_128, AES.MODE_OCB).nonce nonce2 = AES.new(self.key_128, AES.MODE_OCB).nonce self.assertEqual(len(nonce1), 15) self.assertNotEqual(nonce1, nonce2)
Example #6
Source File: test_CBC.py From jarvis with GNU General Public License v2.0 | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_128, self.aes_mode, self.iv_128) self.assertEqual(cipher.block_size, AES.block_size)
Example #7
Source File: test_CBC.py From jarvis with GNU General Public License v2.0 | 5 votes |
def test_block_size_64(self): cipher = DES3.new(self.key_192, self.des3_mode, self.iv_64) self.assertEqual(cipher.block_size, DES3.block_size)
Example #8
Source File: test_GCM.py From jarvis with GNU General Public License v2.0 | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_128, AES.MODE_GCM, nonce=self.nonce_96) self.assertEqual(cipher.block_size, AES.block_size)
Example #9
Source File: test_CCM.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size(self): cipher = AES.new(self.key_128, AES.MODE_CCM, nonce=self.nonce_96) self.assertEqual(cipher.block_size, AES.block_size)
Example #10
Source File: test_EAX.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96) self.assertEqual(cipher.block_size, AES.block_size)
Example #11
Source File: test_EAX.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_64(self): cipher = DES3.new(self.key_192, AES.MODE_EAX, nonce=self.nonce_96) self.assertEqual(cipher.block_size, DES3.block_size)
Example #12
Source File: test_CTR.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_128, AES.MODE_CTR, counter=self.ctr_128) self.assertEqual(cipher.block_size, AES.block_size)
Example #13
Source File: test_CTR.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_64(self): cipher = DES3.new(self.key_192, DES3.MODE_CTR, counter=self.ctr_64) self.assertEqual(cipher.block_size, DES3.block_size)
Example #14
Source File: test_OCB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_128, AES.MODE_OCB, nonce=self.nonce_96) self.assertEqual(cipher.block_size, AES.block_size) # By default, a 15 bytes long nonce is randomly generated nonce1 = AES.new(self.key_128, AES.MODE_OCB).nonce nonce2 = AES.new(self.key_128, AES.MODE_OCB).nonce self.assertEqual(len(nonce1), 15) self.assertNotEqual(nonce1, nonce2)
Example #15
Source File: test_CBC.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_128, self.aes_mode, self.iv_128) self.assertEqual(cipher.block_size, AES.block_size)
Example #16
Source File: test_CBC.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_64(self): cipher = DES3.new(self.key_192, self.des3_mode, self.iv_64) self.assertEqual(cipher.block_size, DES3.block_size)
Example #17
Source File: test_GCM.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_128, AES.MODE_GCM, nonce=self.nonce_96) self.assertEqual(cipher.block_size, AES.block_size)
Example #18
Source File: test_EAX.py From jarvis with GNU General Public License v2.0 | 5 votes |
def test_block_size_64(self): cipher = DES3.new(self.key_192, AES.MODE_EAX, nonce=self.nonce_96) self.assertEqual(cipher.block_size, DES3.block_size)
Example #19
Source File: test_EAX.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_64(self): cipher = DES3.new(self.key_192, AES.MODE_EAX, nonce=self.nonce_96) self.assertEqual(cipher.block_size, DES3.block_size)
Example #20
Source File: test_CTR.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_128, AES.MODE_CTR, counter=self.ctr_128) self.assertEqual(cipher.block_size, AES.block_size)
Example #21
Source File: test_CTR.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_64(self): cipher = DES3.new(self.key_192, DES3.MODE_CTR, counter=self.ctr_64) self.assertEqual(cipher.block_size, DES3.block_size)
Example #22
Source File: test_SIV.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_256, AES.MODE_SIV, nonce=self.nonce_96) self.assertEqual(cipher.block_size, AES.block_size)
Example #23
Source File: test_OCB.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_128, AES.MODE_OCB, nonce=self.nonce_96) self.assertEqual(cipher.block_size, AES.block_size) # By default, a 15 bytes long nonce is randomly generated nonce1 = AES.new(self.key_128, AES.MODE_OCB).nonce nonce2 = AES.new(self.key_128, AES.MODE_OCB).nonce self.assertEqual(len(nonce1), 15) self.assertNotEqual(nonce1, nonce2)
Example #24
Source File: test_CBC.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_64(self): cipher = DES3.new(self.key_192, self.des3_mode, self.iv_64) self.assertEqual(cipher.block_size, DES3.block_size)
Example #25
Source File: test_GCM.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_block_size_128(self): cipher = AES.new(self.key_128, AES.MODE_GCM, nonce=self.nonce_96) self.assertEqual(cipher.block_size, AES.block_size)
Example #26
Source File: aes.py From python-graphenelib with MIT License | 5 votes |
def encrypt(self, raw): raw = self._pad(AESCipher.str_to_bytes(raw)) iv = Random.new().read(AES.block_size) cipher = AES.new(self.key, AES.MODE_CBC, iv) return base64.b64encode(iv + cipher.encrypt(raw)).decode("utf-8")
Example #27
Source File: aes.py From python-graphenelib with MIT License | 5 votes |
def decrypt(self, enc): enc = base64.b64decode(enc) iv = enc[: AES.block_size] cipher = AES.new(self.key, AES.MODE_CBC, iv) return self._unpad(cipher.decrypt(enc[AES.block_size :])).decode("utf-8")
Example #28
Source File: NetflixCredentials.py From plugin.video.netflix with MIT License | 5 votes |
def encode(self, raw): """ Encodes data :param data: Data to be encoded :type data: str :returns: string -- Encoded data """ raw = bytes(Padding.pad(data_to_pad=raw.encode('utf-8'), block_size=self.bs)) iv = Random.new().read(AES.block_size) cipher = AES.new(self.crypt_key, AES.MODE_CBC, iv) return base64.b64encode(iv + cipher.encrypt(raw))
Example #29
Source File: NetflixCredentials.py From plugin.video.netflix with MIT License | 5 votes |
def decode(self, enc): """ Decodes data :param data: Data to be decoded :type data: str :returns: string -- Decoded data """ enc = base64.b64decode(enc) iv = enc[:AES.block_size] cipher = AES.new(self.crypt_key, AES.MODE_CBC, iv) decoded = Padding.unpad( padded_data=cipher.decrypt(enc[AES.block_size:]), block_size=self.bs).decode('utf-8') return decoded
Example #30
Source File: cryptodome.py From keylime with BSD 2-Clause "Simplified" License | 5 votes |
def _pad(s): ''' Returns the string padded with its length such that is a multiple of 16 Appends 10* at the bit level. Following ISO/IEC 9797-1 - padding mode 2 ''' # Let's only encode if its not a byte try: s = s.encode('utf-8') # except AttributeError: pass pad_len = AES.block_size - (len(s) % AES.block_size) - 1 padding = b'\x80'+b'\0'*pad_len return s + padding