import M2Crypto.RSA import M2Crypto.EVP import time import base64, urllib ts = int(time.time()) user = 'equinox' data = '%d:%s' % (ts, user) algo = 'sha256' digest = M2Crypto.EVP.MessageDigest(algo) digest.update(data) digval = digest.final() key = M2Crypto.RSA.load_key('rsa.pem') signature = key.sign(digval, algo = algo) print urllib.urlencode([('user', user), ('ts', ts), ('signature', base64.urlsafe_b64encode(signature))])