python模块-hmac

Hmac算法:Keyed-Hashing for Message Authentication。它通过一个标准算法,在计算哈希的过程中,把key混入计算过程中。

import time
from hashlib import sha1
import hmac
import base64

username="xxxx"
apiKey="yyyy"
date=time.strftime("%a, %d %b %Y %H:%M:%S GMT",time.localtime())
my_sign = hmac.new(apiKey,date,sha1).digest()
password = base64.b64encode(my_sign)
print password

shell:

#!/bin/bash

username="XXXX"

apiKey="YYYY"

date=`env LANG="en_US.UTF-8" date -u "+%a, %d %b %Y %H:%M:%S GMT"`

password=`echo -en "$date" | openssl dgst -sha1 -hmac $apiKey -binary | openssl enc -base64`

猜你喜欢

转载自www.cnblogs.com/hanjiajiejie/p/9050466.html