Skip to content

Instantly share code, notes, and snippets.

Created Dec 16, 2015
Embed
What would you like to do?
TryCF Gist
<cfscript>
function genToken(numeric numOfbytes=32)
{
var hex = "";
for (var byte = 0; byte < numOfbytes; byte++)
{
var randomByte = RandRange(0, 255, 'SHA1PRNG');
var randomHex = FormatBaseN(randomByte,16);
hex &= len(randomHex) == 1 ? 0 & randomHex : randomHex;
}
var binary = binaryDecode(hex, 'hex');
var base64 = toBase64(binary);
var base64url = replaceList(base64, "+,/,=", "-,_,");
return base64url;
}
for ( i = 1 ; i <= 25 ; i++)
writeOutput("#i#: " & genToken() & "<br>");
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment