51 public function get($raw =
false) {
53 throw new \RuntimeException(
'Secret key is not set');
61 if ($this->key[0] ===
'z') {
63 $base64 = strtr(substr($this->key, 1),
'-_',
'+/');
64 $key = base64_decode($base64);
74 return hex2bin($this->key);
86 $secret = $this->
get();
87 if ($secret[0] !==
'z') {
88 $rand_max = getrandmax();
89 if ($rand_max < pow(2, 16)) {
92 if ($rand_max < pow(2, 32)) {
112 $table->
set(self::CONFIG_KEY, $key);
114 return new self($key);
126 $key = $table->
get(self::CONFIG_KEY);
128 throw new \InstallationException(
'Site secret is not in the config table.');
131 return new self($key);
142 $key = $config->{self::CONFIG_KEY};
148 unset(
$config->{self::CONFIG_KEY});
150 return new self($key);
static fromDatabase(ConfigTable $table)
Create from config/storage.
Manages a site-specific secret key, encoded as a 32 byte string "secret".
__construct($key)
Constructor.
$config
Advanced site settings, debugging section.
getStrength()
Get the strength of the site secret.
static fromConfig(ElggConfig $config)
Create from a config value.
get($name)
Gets a configuration value.
getRandomString($length, $chars=null)
Generate a random string of specified length.
static regenerate(ElggCrypto $crypto, ConfigTable $table)
Initialise the site secret (32 bytes: "z" to indicate format + 186-bit key in Base64 URL) and save to...
set($name, $value)
Add or update a config setting.
Manipulates values in the dbprefix_config table.