вторник, 18 ноября 2014 г.

HMAC-SHA1

[HMAC-SHA1]$ cat test1.py
#!/usr/bin/env python

import base64
import hmac
import hashlib
import urllib
import time

domain = "localhost";
port = "";
user = "u1";
group = "g1";
timestamp = int(time.time())

query = "?user=" + user + "&group=" + group + "&timestamp=" + timestamp;
sharedKey = "qwerty";

hash = hmac.new(sharedKey, query, hashlib.sha1).digest()
b = base64.encodestring(hash)
b = b.rstrip()

print "base64 string: " + b

print "signature: " + urllib.quote_plus(b.encode('utf8'))

[HMAC-SHA1]$ ./test1.py
base64 string: nU7YmyYLQ/HZ+GYLxdpva276wVk=
signature: nU7YmyYLQ%2FHZ%2BGYLxdpva276wVk%3D

Комментариев нет:

Отправить комментарий