Yoast\WP\SEO\MyYoast_Client\Infrastructure\Crypto
Key_Pair_Manager::get_stored_key_pair
Retrieves a stored key pair, decrypting the private key.
Метод класса: Key_Pair_Manager{}
Хуков нет.
Возвращает
Key_Pair|null. The key pair or null if not stored.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_stored_key_pair( $purpose ): ?Key_Pair;
- $purpose(строка) (обязательный)
- One of the PURPOSE_* constants.
Код Key_Pair_Manager::get_stored_key_pair() Key Pair Manager::get stored key pair Yoast 27.7
private function get_stored_key_pair( string $purpose ): ?Key_Pair {
$stored = \get_option( $this->get_option_key( $purpose ), [] );
if ( ! \is_array( $stored ) || empty( $stored['public_key'] ) || empty( $stored['private_key_encrypted'] ) || empty( $stored['kid'] ) ) {
$this->cached_key_pairs[ $this->get_option_key( $purpose ) ] = null;
return null;
}
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode -- Decoding our own base64-encoded key.
$public_key = \base64_decode( $stored['public_key'], true );
$private_key = $this->encryption->decrypt(
$stored['private_key_encrypted'],
self::CONTEXT_PREFIX . $purpose,
);
if ( $public_key === false || \strlen( $public_key ) !== \SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES ) {
$this->cached_key_pairs[ $this->get_option_key( $purpose ) ] = null;
return null;
}
$key_pair = new Key_Pair( $public_key, $private_key, $stored['kid'] );
$this->cached_key_pairs[ $this->get_option_key( $purpose ) ] = $key_pair;
return $key_pair;
}