Ejemplo n.º 1
0
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"
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    def set_security_cookie(self, key, value, expires_days=1, path="/", domain=None):
        """set security cookie's value

        :param key: cookie's key
        :param value: cookie's value
        :param expires_days: cookie's expires days
        :param path: cookie's value path
        :param domain: cookie's domain
        :return: None

        """
        des = StrEncryption()
        security_key = self.__settings.get("cookie", COOKIE_SECURITY_DEFAULT_STRING)
        des.input_key(security_key)
        security_value = des.encode(value)
        self.set_cookie(key, security_value, expires_days, path, domain)
Ejemplo n.º 5
0
    def set_security_cookie(self, key, value, expires_days=1, path="/", domain=None):
        """set security cookie's value

        :param key: cookie's key
        :param value: cookie's value
        :param expires_days: cookie's expires days
        :param path: cookie's value path
        :param domain: cookie's domain
        :return: None

        """
        des = StrEncryption()
        security_key = self.__settings.get("cookie", COOKIE_SECURITY_DEFAULT_STRING)
        des.input_key(security_key)
        security_value = des.encode(value)
        self.set_cookie(key, security_value, expires_days, path, domain)