public function Lockr::generateKey in Lockr 7.3
Generates a new random key.
Parameters
int $size:
Return value
string
File
- vendor/
lockr/ lockr/ src/ Lockr.php, line 279
Class
Namespace
LockrCode
public function generateKey($size = 256) {
$query = <<<'EOQ'
query RandomKey($size: KeySize) {
randomKey(size: $size)
}
EOQ;
if ($size !== 256 && $size !== 192 && $size !== 128) {
throw new \Exception("Invalid key size: {$size}");
}
$t0 = microtime(true);
$data = $this->client
->query([
'query' => $query,
'variables' => [
'size' => "AES{$size}",
],
]);
$t1 = microtime(true);
$this->client
->getStats()
->lockrCallCompleted('generate_key', $t1 - $t0);
return base64_decode($data['randomKey']);
}