常见的加密算法-Itsdangerous

加密算法之Itsdangerous

  • 安装

    pip install itsdangerous
    
  • 代码块

    from itsdangerous import TimedJSONWebSignatureSerializer as serializer
    class ItsdangerouSecret:
        # 初始化
        def __init__(self,salt='123456789',expir=6):
            self.salt = salt # 盐值
            self.expir = expir # 过期时间 单位秒
    
        # 加密  raw 是一个对象
        def encry(self,raw):
            try:
                obj = serializer(self.salt, expires_in=self.expir)
                res = obj.dumps(raw)
                token = res.decode()
                return token
        	except:
            	retrun ''
    
    
        # 解密  raw是字符串 
        def decry(self,raw):
            try:
                obj = serializer(self.salt, expires_in=self.expir)
                return obj.loads(raw)
            except:
                return ''  
    
posted @ 2019-10-27 21:04  巫小诗  阅读(270)  评论(0编辑  收藏  举报