def test_decrypt_data(self):
     encrypted = memcache_crypt.encrypt_data('mykey', 'mysecret', 'Testz')
     self.assertEqual(
         memcache_crypt.decrypt_data('mykey', 'mysecret', encrypted),
         'Testz')
     self.assertEqual(
         memcache_crypt.decrypt_data('mykey', 'mysecret', 'Not Encrypted!'),
         'Not Encrypted!')
 def test_decrypt_data(self):
     encrypted = memcache_crypt.encrypt_data('mykey', 'mysecret', 'Testz')
     self.assertEqual(
         memcache_crypt.decrypt_data('mykey', 'mysecret', encrypted),
         'Testz')
     self.assertEqual(
         memcache_crypt.decrypt_data('mykey', 'mysecret',
                                     'Not Encrypted!'),
         'Not Encrypted!')
 def test_encryption(self):
     keys = self._setup_keys(b'ENCRYPT')
     # what you put in is what you get out
     for data in [b'data', b'1234567890123456', b'\x00\xFF' * 13
                  ] + [six.int2byte(x % 256) * x for x in range(768)]:
         crypt = memcache_crypt.encrypt_data(keys['ENCRYPTION'], data)
         decrypt = memcache_crypt.decrypt_data(keys['ENCRYPTION'], crypt)
         self.assertEqual(data, decrypt)
         self.assertRaises(memcache_crypt.DecryptError,
                           memcache_crypt.decrypt_data,
                           keys['ENCRYPTION'], crypt[:-1])
 def test_encryption(self):
     keys = self._setup_keys(b'ENCRYPT')
     # what you put in is what you get out
     for data in [b'data', b'1234567890123456', b'\x00\xFF' * 13
                  ] + [six.int2byte(x % 256) * x for x in range(768)]:
         crypt = memcache_crypt.encrypt_data(keys['ENCRYPTION'], data)
         decrypt = memcache_crypt.decrypt_data(keys['ENCRYPTION'], crypt)
         self.assertEqual(data, decrypt)
         self.assertRaises(memcache_crypt.DecryptError,
                           memcache_crypt.decrypt_data,
                           keys['ENCRYPTION'], crypt[:-1])
Exemplo n.º 5
0
 def _protect_cache_value(self, token, data):
     """ Encrypt or sign data if necessary. """
     try:
         if self._memcache_security_strategy == "ENCRYPT":
             return memcache_crypt.encrypt_data(token, self._memcache_secret_key, data)
         elif self._memcache_security_strategy == "MAC":
             return memcache_crypt.sign_data(token, data)
         else:
             return data
     except:
         msg = "Failed to encrypt/sign cache data."
         self.LOG.exception(msg)
         return data
Exemplo n.º 6
0
 def _protect_cache_value(self, token, data):
     """ Encrypt or sign data if necessary. """
     try:
         if self._memcache_security_strategy == 'ENCRYPT':
             return memcache_crypt.encrypt_data(token,
                                                self._memcache_secret_key,
                                                data)
         elif self._memcache_security_strategy == 'MAC':
             return memcache_crypt.sign_data(token, data)
         else:
             return data
     except:
         msg = 'Failed to encrypt/sign cache data.'
         self.LOG.exception(msg)
         return data
 def test_encrypt_data(self):
     expected = '{ENCRYPT:AES256}'
     self.assertEqual(
         memcache_crypt.encrypt_data('mykey', 'mysecret',
                                     'This is a test!')[:16],
         expected)
 def test_encrypt_data(self):
     expected = '{ENCRYPT:AES256}'
     self.assertEqual(
         memcache_crypt.encrypt_data('mykey', 'mysecret',
                                     'This is a test!')[:16], expected)