def cast_byte_decrypt(self, input_byte, encrypt_key): pbk = PBKDF2HMAC(hashes.SHA256, self.__salt_size, self.__salt, self.__iteration_count, self._backend) pbk_key = pbk.derive(encrypt_key.encode()) decryptor = Cipher( CAST5(pbk_key), modes.CBC(self.__IV[0:8]), self._backend ).decryptor() cipher_text = decryptor.update(input_byte) + decryptor.finalize() un_padder = padding.PKCS7(CAST5.block_size).unpadder() un_padded_data = un_padder.update(cipher_text) + un_padder.finalize() return un_padded_data
def test_invalid_key_type(self): with pytest.raises(TypeError, match="key must be bytes"): CAST5(u"0" * 10)
def test_invalid_key_size(self): with pytest.raises(ValueError): CAST5(binascii.unhexlify(b"0" * 34))
def test_key_size(self, key, keysize): cipher = CAST5(binascii.unhexlify(key)) assert cipher.key_size == keysize
def test_invalid_key_type(self): with pytest.raises(TypeError, match="key must be bytes"): CAST5("0" * 10) # type: ignore[arg-type]
def _make_cipher(self, passphrase): key = self.make_key(passphrase) iv = self.make_iv(passphrase) cipher = Cipher(CAST5(key), CBC(iv), backend=default_backend()) return cipher