这是官方给的说明 (emmm......)
签名方式: 先用sha加密secretkey,然后根据加密过的secretkey把请求的参数签名,请求参数按照ascii值排序加密,通过md5填充16位加密
def md5(data)
Digest::MD5.hexdigest(data)
end
def sha(data)
secret_key = Digest::SHA256.hexdigest(@secret_key)
sha256 = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'),secret_key,data)
return md5(sha256)
end
def __fill(self, value, lenght, fillByte):
if len(value) >= lenght:
return value
else:
fillSize = lenght - len(value)
return value + chr(fillByte) * fillSize
def __doXOr(self, s, value):
slist = list(s)
for index in xrange(len(slist)):
slist[index] = chr(ord(slist[index]) ^ value)
return "".join(slist)
def __hmacSign(self, aValue, aKey):
keyb = struct.pack("%ds" % len(aKey), aKey)
value = struct.pack("%ds" % len(aValue), aValue)
k_ipad = self.__doXOr(keyb, 0x36)
k_opad = self.__doXOr(keyb, 0x5c)
k_ipad = self.__fill(k_ipad, 64, 54)
k_opad = self.__fill(k_opad, 64, 92)
m = hashlib.md5()
m.update(k_ipad)
m.update(value)
dg = m.digest()
m = hashlib.md5()
m.update(k_opad)
subStr = dg[0:16]
m.update(subStr)
dg = m.hexdigest()
return dg
def __digest(self, aValue):
value = struct.pack("%ds" % len(aValue), aValue)
print value
h = sha.new()
h.update(value)
dg = h.hexdigest()
return dg