Home  >  Article  >  Backend Development  >  python 数据加密代码

python 数据加密代码

WBOY
WBOYOriginal
2016-06-06 11:27:021146browse
1、hashlib
import hashlib
#创建一个哈希对象
md = hashlib.md5()
#md = hashlib.sha1()
#md = hashlib.sha224()
#md = hashlib.sha25()
#md = hashlib.sha384()
#md = hashlib.sha512()
1.1 hashlib.update(arg)
1.2 hashlib.digest() #返回数字形式的哈希
1.3 hashlib.hexdigest() #返回16进制的哈希
1.4 hashlib.copy()
一般而言,用hashlib.hexdigest()就可以了
2、hmac
2.1 hmac.new(key[, msg[, digestmod]])
2.2 hmac.update(msg)
2.3 hmac.digest()
2.4 hmac.hexdigest()
2.5 hmac.copy()
要注意,上面的message都要用bytes,使用string不可以
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn