Skip to content

Instantly share code, notes, and snippets.

@krciga22
Created May 18, 2015 02:29
Show Gist options
  • Save krciga22/8c0bdea99b28cf592589 to your computer and use it in GitHub Desktop.
Save krciga22/8c0bdea99b28cf592589 to your computer and use it in GitHub Desktop.
Generate a random key of N size
<?PHP
// Generate a random key of N size
$keySize = 256;
$key = bin2hex(openssl_random_pseudo_bytes($keySize/2));
echo 'Generating Key of size: '.$keySize;
echo '<br />Key: '.$key;
echo '<br />Length: '.strlen($key);
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment