Wait for bloom
时光不语,静待花开

1.hashlib

1 #!/usr/bin/python
2 import hashlib
3 hash = hashlib.sha384()#支持 md5/sha1/sha224/sha256等,用法一致
4 hash.update(b'test')
5 print(hash.digest()) #二进制hash
6 print(hash.hexdigest())  #十六进制hash
View Code

 2.hmac

def new(key, msg=None, digestmod=''):
"""Create a new hashing object and return it.

key: bytes or buffer, The starting key for the hash.
msg: bytes or buffer, Initial input for the hash, or None.
digestmod: A hash name suitable for hashlib.new(). *OR*
A hashlib constructor returning a new hash object. *OR*
A module supporting PEP 247.

Required as of 3.8, despite its position after the optional
msg argument. Passing it as a keyword argument is
recommended, though not required for legacy API reasons.

You can now feed arbitrary bytes into the object using its update()
method, and can ask for the hash value at any time by calling its digest()
or hexdigest() methods.
"""
return HMAC(key, msg, digestmod)
翻译:创建一个新的hash对象并返回
key:二进制或buffer,hash开始的key
msg:二进制或buffer,初始传入的hash
模式:hash的加密方法,如md5/sha1/sha224/sha256
 1 #!/usr/bin/python
 2 import hashlib,hmac
 3 hash = hashlib.sha384()#支持 md5/sha1/sha224/sha256等,用法一致
 4 hash.update(b'admin')
 5 print(hash)
 6 print(hash.digest()) #二进制hash
 7 print(hash.hexdigest())  #十六进制hash
 8 
 9 h=hmac.new(b'test',b'test_true',digestmod='md5')
10 print(h.hexdigest())
View Code

 

posted on 2024-01-30 14:55  Little-Girl  阅读(25)  评论(0)    收藏  举报