def test_aes_decrypt_with_unicode(self):
        """Testing aes_decrypt with Unicode data"""
        expected_message = ('The data to decrypt must be of type "bytes", '
                            'not "<class \'str\'>"')

        with self.assertRaisesMessage(TypeError, expected_message):
            aes_decrypt('abc')
    def test_aes_decrypt_with_unicode(self):
        """Testing aes_decrypt with Unicode data"""
        expected_message = (
            'The data to decrypt must be of type "bytes", not "%s"' %
            six.text_type)

        with self.assertRaisesMessage(TypeError, expected_message):
            aes_decrypt('abc')
    def test_aes_decrypt_with_custom_key_unicode(self):
        """Testing aes_decrypt with custom key as Unicode"""
        encrypted = (
            b'\x9cd$e\xb1\x9e\xe0z\xb8[\x9e!\xf2h\x90\x8d\x82f%G4\xc2\xf0'
            b'\xda\x8dr\x81ER?S6\x12%7\x98\x89\x90'
        )
        expected_message = ('The encryption key must be of type "bytes", '
                            'not "<class \'str\'>"')

        with self.assertRaisesMessage(TypeError, expected_message):
            aes_decrypt(encrypted, key='abc')
Example #4
0
 def test_aes_encrypt(self):
     """Testing aes_encrypt"""
     # The encrypted value will change every time, since the iv changes,
     # so we can't compare a direct value. Instead, we need to ensure that
     # we can decrypt what we encrypt.
     self.assertEqual(aes_decrypt(aes_encrypt(self.PLAIN_TEXT)),
                      self.PLAIN_TEXT)
Example #5
0
 def test_aes_encrypt(self):
     """Testing aes_encrypt"""
     # The encrypted value will change every time, since the iv changes,
     # so we can't compare a direct value. Instead, we need to ensure that
     # we can decrypt what we encrypt.
     self.assertEqual(aes_decrypt(aes_encrypt(self.PLAIN_TEXT)),
                      self.PLAIN_TEXT)
 def test_aes_encrypt_with_unicode(self):
     """Testing aes_encrypt with Unicode string"""
     # The encrypted value will change every time, since the iv changes,
     # so we can't compare a direct value. Instead, we need to ensure that
     # we can decrypt what we encrypt.
     encrypted = aes_encrypt(self.PLAIN_TEXT_UNICODE)
     self.assertIsInstance(encrypted, bytes)
     self.assertEqual(aes_decrypt(encrypted), self.PLAIN_TEXT_BYTES)
Example #7
0
    def test_aes_encrypt_with_custom_key(self):
        """Testing aes_encrypt with custom key"""
        # The encrypted value will change every time, since the iv changes,
        # so we can't compare a direct value. Instead, we need to ensure that
        # we can decrypt what we encrypt.
        encrypted = aes_encrypt(self.PLAIN_TEXT, key=self.CUSTOM_KEY)

        self.assertEqual(aes_decrypt(encrypted, key=self.CUSTOM_KEY),
                         self.PLAIN_TEXT)
Example #8
0
    def test_aes_decrypt(self):
        """Testing aes_decrypt"""
        # The encrypted value was made with PyCrypto, to help with
        # compatibility testing from older installs.
        encrypted = (
            b'\xfb\xdc\xb5h\x15\xa1\xb2\xdc\xec\xf1\x14\xa9\xc6\xab\xb2J\x10'
            b'\'\xd4\xf6&\xd4k9\x82\xf6\xb5\x8bmu\xc8E\x9c\xac\xc5\x04@B')

        self.assertEqual(aes_decrypt(encrypted), self.PLAIN_TEXT)
Example #9
0
    def test_aes_encrypt_with_custom_key(self):
        """Testing aes_encrypt with custom key"""
        # The encrypted value will change every time, since the iv changes,
        # so we can't compare a direct value. Instead, we need to ensure that
        # we can decrypt what we encrypt.
        encrypted = aes_encrypt(self.PLAIN_TEXT, key=self.CUSTOM_KEY)

        self.assertEqual(aes_decrypt(encrypted, key=self.CUSTOM_KEY),
                         self.PLAIN_TEXT)
Example #10
0
    def test_aes_decrypt_with_custom_key(self):
        """Testing aes_decrypt with custom key"""
        # The encrypted value was made with PyCrypto, to help with
        # compatibility testing from older installs.
        encrypted = (
            b'\x9cd$e\xb1\x9e\xe0z\xb8[\x9e!\xf2h\x90\x8d\x82f%G4\xc2\xf0'
            b'\xda\x8dr\x81ER?S6\x12%7\x98\x89\x90')

        self.assertEqual(aes_decrypt(encrypted, key=self.CUSTOM_KEY),
                         self.PLAIN_TEXT)
Example #11
0
    def test_aes_decrypt(self):
        """Testing aes_decrypt"""
        # The encrypted value was made with PyCrypto, to help with
        # compatibility testing from older installs.
        encrypted = (
            b'\xfb\xdc\xb5h\x15\xa1\xb2\xdc\xec\xf1\x14\xa9\xc6\xab\xb2J\x10'
            b'\'\xd4\xf6&\xd4k9\x82\xf6\xb5\x8bmu\xc8E\x9c\xac\xc5\x04@B'
        )

        self.assertEqual(aes_decrypt(encrypted), self.PLAIN_TEXT)
Example #12
0
 def test_encrypt(self):
     """Testing encrypt (deprecated)"""
     with warnings.catch_warnings(record=True) as w:
         # The encrypted value will change every time, since the iv changes,
         # so we can't compare a direct value. Instead, we need to ensure
         # that we can decrypt what we encrypt.
         self.assertEqual(aes_decrypt(encrypt(self.PLAIN_TEXT)),
                          self.PLAIN_TEXT)
         self.assertEqual(
             six.text_type(w[0].message),
             'encrypt() is deprecated. Use aes_encrypt() instead.')
Example #13
0
 def test_encrypt(self):
     """Testing encrypt (deprecated)"""
     with warnings.catch_warnings(record=True) as w:
         # The encrypted value will change every time, since the iv changes,
         # so we can't compare a direct value. Instead, we need to ensure
         # that we can decrypt what we encrypt.
         self.assertEqual(aes_decrypt(encrypt(self.PLAIN_TEXT)),
                          self.PLAIN_TEXT)
         self.assertEqual(
             six.text_type(w[0].message),
             'encrypt() is deprecated. Use aes_encrypt() instead.')
Example #14
0
    def test_aes_decrypt_with_custom_key(self):
        """Testing aes_decrypt with custom key"""
        # The encrypted value was made with PyCrypto, to help with
        # compatibility testing from older installs.
        encrypted = (
            b'\x9cd$e\xb1\x9e\xe0z\xb8[\x9e!\xf2h\x90\x8d\x82f%G4\xc2\xf0'
            b'\xda\x8dr\x81ER?S6\x12%7\x98\x89\x90'
        )

        self.assertEqual(aes_decrypt(encrypted, key=self.CUSTOM_KEY),
                         self.PLAIN_TEXT)
    def test_encrypt(self):
        """Testing encrypt (deprecated)"""
        message = 'encrypt() is deprecated. Use aes_encrypt() instead.'

        with self.assertWarns(message=message):
            # The encrypted value will change every time, since the iv changes,
            # so we can't compare a direct value. Instead, we need to ensure
            # that we can decrypt what we encrypt.
            encrypted = encrypt(self.PLAIN_TEXT_BYTES)

        self.assertIsInstance(encrypted, bytes)
        self.assertEqual(aes_decrypt(encrypted), self.PLAIN_TEXT_BYTES)