Yoast\WP\SEO\MyYoast_Client\Infrastructure\Crypto

Key_Pair_Manager::generate_key_pairpublicYoast 1.0

Generates a new Ed25519 key pair in memory without persisting it.

Use store_key_pair() to persist after confirming success of external operations.

Метод класса: Key_Pair_Manager{}

Хуков нет.

Возвращает

Key_Pair. The generated key pair.

Использование

$Key_Pair_Manager = new Key_Pair_Manager();
$Key_Pair_Manager->generate_key_pair(): Key_Pair;

Код Key_Pair_Manager::generate_key_pair() Yoast 27.7

public function generate_key_pair(): Key_Pair {
	$keypair = '';

	try {
		$keypair     = \sodium_crypto_sign_keypair();
		$public_key  = \sodium_crypto_sign_publickey( $keypair );
		$private_key = \sodium_crypto_sign_secretkey( $keypair );
		$kid         = Base64url::encode( \hash( 'sha256', $public_key, true ) );

		return new Key_Pair( $public_key, $private_key, $kid );
	}
	catch ( SodiumException $e ) {
		// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Internal exception message.
		throw new Encryption_Exception( 'Key pair generation failed: ' . $e->getMessage(), 0, $e );
	}
	finally {
		if ( $keypair !== '' ) {
			try {
				\sodium_memzero( $keypair );
			}
			catch ( SodiumException $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch -- Best-effort cleanup.
				// Best-effort: keypair will be freed when it goes out of scope.
			}
		}
	}
}