标签:
hmac模块
用于加密,部分方法定义如下:
def update(self, msg):
"""Update this hashing object with the string msg.
使其带字符串的msg更新这个哈希对象
"""
self.inner.update(msg)
def digest(self):
"""Return the hash value of this hashing object.
This returns a string containing 8-bit data. The object is
not altered in any way by this function; you can continue
updating the object after calling this function.
返回哈希对象的值。返回一个8位数据。这个对象不会被这个函数用任何方式改变,你可以在调用此方法后继续更新这个对象
"""
h = self._current()
return h.digest()
def hexdigest(self):
"""Like digest(), but returns a string of hexadecimal digits instead.
和digest()方法一样,但是返回一个16进制的字符串
"""
h = self._current()
return h.hexdigest()
def new(key, msg = None, digestmod = None):
"""Create a new hashing object and return it.
key: The starting key for the hash.
msg: if available, will immediately be hashed into the object‘s starting
state.
You can now feed arbitrary strings into the object using its update()
method, and can ask for the hash value at any time by calling its digest()
method.
创建一个哈希对象然后返回它。key:哈希起始的key msg:如果可用,将马上被hash进对象的开始状态 你可以使用update方法提供任意的字符串进对象,
可以在调用digest后在任何时间调用hash值
"""
return HMAC(key, msg, digestmod)
实验实例
import
hmac
h
=
hmac.new(
‘liqx‘
) #将信息转化为hash值
h.update(
‘2015-11-22 23:41:30‘
) #更新hash值(加盐)
print
h.hexdigest() #返回hash值(16进制)
标签:
原文地址:http://www.cnblogs.com/liqxd/p/4987121.html