Created
October 20, 2016 13:25
-
-
Save mohsin/40bd831ec7380bc44e4af1b898eaa9f8 to your computer and use it in GitHub Desktop.
Random secret generator for AES-256-CBC
This file contains hidden or 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
//JS Version | |
var charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', | |
randomString = '' | |
for (var i = 0; i < length; i++) { | |
var randomPos = Math.floor(Math.random() * charSet.length) | |
randomString += charSet.substring(randomPos, randomPos + 1) | |
} | |
return randomString | |
// PHP version | |
$charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
$randomString = ''; | |
for ($i = 0; $i < 32; $i++) { | |
$randomPos = floor(((float)rand()/(float)getrandmax()) * strlen($charSet)); | |
$randomString .= substr($charSet, $randomPos, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment