Created
September 13, 2012 13:29
-
-
Save aezell/3714268 to your computer and use it in GitHub Desktop.
nonce creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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