/** * Generate key by time * * @access private * @param string $seed * @param integer|string $delta strtotime * @return string */ private function generateByTime($seed, $delta) { $end = strtotime($delta); $hash = hash_hmac("sha256", $seed, $this->signing_key, TRUE); $iters = 0; while (time() < $end) { $hash = hash_hmac("sha256", $hash, $this->signing_key, TRUE); $iters += 1; } $this->iterations = $iters; return Fernet::base64url_encode($hash); }
/** * Gets the site-specific encryption and signing key. * * If the key does not exist, it is automatically generated. * * @return string the site-specific encryption and signing key * as a base64url encoded string */ protected static function getKey() { $store = StoreManager::instance(); $key = $store->getSetting('oauth-fernet'); if ($key == NULL) { $rand = new Random(); $key = Fernet::base64url_encode($rand->bytes(32)); $store->setSetting('oauth-fernet', $key); } return $key; }
/** * Gets the site-specific encryption and signing key. * * If the key does not exist, it is automatically generated. * * @return string the site-specific encryption and signing key * as a base64url encoded string */ private static function getSiteToken() { $store = StoreManager::instance(); $site_token = $store->getSetting('site-token'); if ($site_token == NULL) { $rand = new Random(); $site_token = Fernet::base64url_encode($rand->bytes(32)); $store->setSetting('site-token', $site_token); } return $site_token; }