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`


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM