Skip to content

Instantly share code, notes, and snippets.

@aezell
Created September 13, 2012 13:29
Show Gist options
  • Save aezell/3714268 to your computer and use it in GitHub Desktop.
Save aezell/3714268 to your computer and use it in GitHub Desktop.
nonce creation
# PHP code
function create_nonce()
{
$mt = microtime();
$rand = mt_rand();
return preg_replace('/[^a-zA-Z0-9]/', '', base64_encode(sha1($mt . $rand, true)));
}
# Python code
def create_nonce(self):
"""Create a nonce to be used as part of a signature"""
mt = '%f %d' % math.modf(time.time())
rando = str(random.randint(0, sys.maxint))
return re.sub('/[^a-zA-Z0-9]/', '', b64encode(sha1(mt + rando).digest()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment