Ejemplo n.º 1
0
 def test_AES(self):
     cipher = AESCipher()
     string = "The quick brown fox jumps over the lazy dog."
     ct = cipher.encrypt(string)
     self.assertNotEqual(ct, string)
     pt = cipher.decrypt(ct)
     self.assertEqual(pt, string)
Ejemplo n.º 2
0
 def test_AES(self):
     cipher = AESCipher()
     string = "The quick brown fox jumps over the lazy dog."
     ct = cipher.encrypt(string)
     self.assertNotEqual(ct, string)
     pt = cipher.decrypt(ct)
     self.assertEqual(pt, string)
Ejemplo n.º 3
0
class EncryptedCharField(models.CharField):
    cipher = AESCipher()
    __metaclass__ = models.SubfieldBase

    def to_python(self, value):
        if value is None:
            return value
        if value.startswith("$AES$"):
            return self.cipher.decrypt(value[len("$AES$"):])
        # Warning: This strips all unicode chars. This is a hack because I
        # can not figure out how to get the validation to work right...
        return value.encode('ascii', 'ignore')

    def get_prep_value(self, value):
        return "$AES$" + self.cipher.encrypt(value)
Ejemplo n.º 4
0
 def test_AES_error(self):
     cipher = AESCipher()
     string = "The quick brown fox jumps over the lazy dog."
     ct = cipher.encrypt(string)[:10] + "randomgarbage"
     self.assertRaises(TypeError, cipher.decrypt, ct)
Ejemplo n.º 5
0
 def test_AES_error(self):
     cipher = AESCipher()
     string = "The quick brown fox jumps over the lazy dog."
     ct = cipher.encrypt(string)[:10] + "randomgarbage"
     self.assertRaises(TypeError, cipher.decrypt, ct)