5 use Drupal\Core\State\StateInterface;
6 use Drupal\Component\Utility\Crypt;
9 * Manages the Drupal private key.
16 * @var \Drupal\Core\State\StateInterface
21 * Constructs the token generator.
23 * @param \Drupal\Core\State\StateInterface $state
26 public function __construct(StateInterface $state) {
27 $this->state = $state;
31 * Gets the private key.
36 public function get() {
37 if (!$key = $this->state->get('system.private_key')) {
38 $key = $this->create();
46 * Sets the private key.
49 * The private key to set.
51 public function set($key) {
52 return $this->state->set('system.private_key', $key);
56 * Creates a new private key.
61 protected function create() {
62 return Crypt::randomBytesBase64(55);