Exemple #1
0
    def test_aes(self):
        aes_crypto.DEBUG = True

        aes_crypto.encrypt("this is a test", randoms.bytes(32))
        aes_crypto.encrypt("this is a longer test with more than 16bytes", randoms.bytes(32))
        aes_crypto.encrypt("", randoms.bytes(32))
        aes_crypto.encrypt("testing accented char àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ", randoms.bytes(32))
        aes_crypto.encrypt("testing accented char àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ", randoms.bytes(32))
Exemple #2
0
 def test_aes_on_char(self):
     key = convert.base642bytearray(u'nm5/wK20R45AUtetHJwHTdOigvGTxP7NcH/41YE8AZo=')
     encrypted = aes_crypto.encrypt("kyle", key, salt=convert.base642bytearray("AehqWt1OdEgPJhCx6uylyg=="))
     self.assertEqual(
         json2value(encrypted.decode('utf8')),
         json2value(u'{"type": "AES256", "length": 4, "salt": "AehqWt1OdEgPJhCx6uylyg==", "data": "FXUGxdb9E+4UCKwsIT9ugQ=="}')
     )
Exemple #3
0
 def test_aes_nothing(self):
     key = convert.base642bytearray(u'nm5/wK20R45AUtetHJwHTdOigvGTxP7NcH/41YE8AZo=')
     encrypted = aes_crypto.encrypt("", key, salt=convert.base642bytearray("AehqWt1OdEgPJhCx6uylyg=="))
     self.assertEqual(
         json2value(encrypted.decode('utf8')),
         json2value(u'{"type": "AES256", "length": 0, "salt": "AehqWt1OdEgPJhCx6uylyg=="}')
     )
Exemple #4
0
    def write(self, content):
        """
        :param content: text, or iterable of text
        :return:
        """
        if not self.parent.exists:
            self.parent.create()
        with open(self._filename, "wb") as f:
            if is_list(content) and self.key:
                Log.error(u"list of data and keys are not supported, encrypt before sending to file")

            if is_list(content):
                pass
            elif isinstance(content, text):
                content = [content]
            elif hasattr(content, "__iter__"):
                pass

            for d in content:
                if not is_text(d):
                    Log.error(u"Expecting unicode data only")
                if self.key:
                    from mo_math.aes_crypto import encrypt
                    f.write(encrypt(d, self.key).encode("utf8"))
                else:
                    f.write(d.encode("utf8"))
Exemple #5
0
    def write(self, data):
        if not self.parent.exists:
            self.parent.create()
        with open(self._filename, "wb") as f:
            if is_list(data) and self.key:
                Log.error(
                    u"list of data and keys are not supported, encrypt before sending to file"
                )

            if is_list(data):
                pass
            elif isinstance(data, (binary_type, text)):
                data = [data]
            elif hasattr(data, "__iter__"):
                pass

            for d in data:
                if not is_text(d):
                    Log.error(u"Expecting unicode data only")
                if self.key:
                    from mo_math.aes_crypto import encrypt
                    f.write(encrypt(d, self.key).encode("utf8"))
                else:
                    f.write(d.encode("utf8"))