def test_encrypt(): str_encryption = StrEncryption() str_encryption.input_key("test") _str = "make a test" encode_str = str_encryption.encode(_str) decode_str = str_encryption.decode(encode_str) if _str != decode_str: print(encode_str) print(decode_str) print(_str) assert "encode string error"
def get_security_cookie(self, key, default=None): """get security cookie's value with decode :param key: cookie's key :param default: cookie's default value :return: cookie's value """ cookie = self.get_cookie(key) if not cookie: return default des = StrEncryption() security_key = self.__settings.get("cookie", COOKIE_SECURITY_DEFAULT_STRING) des.input_key(security_key) return des.decode(cookie)