saveToAsciiSafeString(); } /** * Generate RSA key pair for JWT signing. * * @return void * @since 1.0.0 */ private static function generate_key_pair(): void { $config = [ 'digest_alg' => 'sha256', 'private_key_bits' => 2048, 'private_key_type' => OPENSSL_KEYTYPE_RSA, ]; $resource = openssl_pkey_new( $config ); // Check if key generation failed. if ( $resource === false ) { return; } // Extract private key. openssl_pkey_export( $resource, $private_key ); // Extract public key. $details = openssl_pkey_get_details( $resource ); if ( $details === false ) { return; } $public_key = $details['key']; // Store keys (not autoloaded for security). update_option( self::PRIVATE_KEY_OPTION, $private_key, false ); update_option( self::PUBLIC_KEY_OPTION, $public_key, false ); } /** * Regenerate all keys. * * Warning: This will invalidate all existing tokens. * * @return void * @since 1.0.0 */ public static function regenerate_keys(): void { delete_option( self::ENCRYPTION_KEY_OPTION ); delete_option( self::PRIVATE_KEY_OPTION ); delete_option( self::PUBLIC_KEY_OPTION ); // Generate new keys. self::get_encryption_key(); self::get_private_key(); } /** * Delete all keys on uninstall. * * @return void * @since 1.0.0 */ public static function delete_keys(): void { delete_option( self::ENCRYPTION_KEY_OPTION ); delete_option( self::PRIVATE_KEY_OPTION ); delete_option( self::PUBLIC_KEY_OPTION ); } }