在线加密链接
#coding:utf-8
import hmac
import hashlib
class Encry():
def __init__(self,key='', value=''):
self.key = key
self.value = value
def jm_sha256(self):
"""
sha256加密
:param key:
:param value: 加密字符串
:return: 加密结果转换为16进制字符串,并大写
"""
hsobj = hashlib.sha256(self.key.encode("utf-8"))
hsobj.update(self.value.encode("utf-8"))
return hsobj.hexdigest().upper()
def jm_sha256_single(self):
"""
sha256加密
:param value: 加密字符串
:return: 加密结果转换为16进制字符串,并大写
"""
hsobj = hashlib.sha256()
hsobj.update(self.value.encode("utf-8"))
return hsobj.hexdigest().upper()
def hmac_sha256(self):
"""
hmacsha256加密
:param key:
:param value: 加密字符串
:return: 加密结果转换为16进制字符串,并大写
"""
message = self.value.encode("utf-8")
return hmac.new(self.key.encode("utf-8"), message, digestmod=hashlib.sha256).hexdigest().upper()
def hmac_sha256_single(self):
"""
hmacsha256加密
:param value: 加密字符串
:return: 加密结果转换为16进制字符串,并大写
"""
message = self.value.encode("utf-8")
return hmac.new(message, digestmod=hashlib.sha256).hexdigest().upper()
def jm_md5(self):
"""
md5加密
:param key:
:param value: 加密字符串
:return: 加密结果转换为16进制字符串,并大写
"""
hsobj = hashlib.md5(self.key.encode("utf-8"))
hsobj.update(self.value.encode("utf-8"))
return hsobj.hexdigest().upper()
def jm_md5_singlt(self):
"""
md5加密
:param value: 加密字符串
:return: 加密结果转换为16进制字符串,并大写
"""
hsobj = hashlib.md5()
hsobj.update(self.value.encode("utf-8"))
return hsobj.hexdigest().upper()
def hmac_md5(self):
"""
hmacmd5加密
:param key:
:param value: 加密字符串
:return: 加密结果转换为16进制字符串,并大写
"""
message = self.value.encode("utf-8")
return hmac.new(self.key.encode("utf-8"), message, digestmod=hashlib.md5).hexdigest().upper()
def hmac_md5_single(self):
"""
hmacmd5加密
:param value: 加密字符串
:return: 加密结果转换为16进制字符串,并大写
"""
message = self.value.encode("utf-8")
return hmac.new(message, digestmod=hashlib.md5).hexdigest().upper()
if __name__ == '__main__':
aa = Encry(value='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.368detail')
print(aa.jm_sha256().lower())
|