- bin2hex: documentation ( source)
- base64_encode: documentation ( source)
- define: documentation ( source)
<?php
if (!defined('PHP_EOL')) {
define('PHP_EOL', "\r\n");
}
// generate the 32bit byte array
$random_key = openssl_random_pseudo_bytes(32);
// this is it as hex
print "Hex key: " . bin2hex($random_key) . PHP_EOL;
print PHP_EOL;
// this is the base64 string that you want to save
print "Save this string: " . base64_encode($random_key) . PHP_EOL;