encryptService = $encryptService; $this->configService = $configService; } #[OA\Get(path: '/system/api-encrypt', summary: '获取接口加密配置', tags: ['系统配置'])] #[Permission(code: 'system:config:update')] #[DataResponse(description: '获取成功')] public function detail(Request $request): Response { $config = $this->configService->config('api_encrypt_setting', [], ['group_code' => 'system']); $config = is_array($config) ? $config : []; return Json::success('获取成功', [ 'enabled' => (int) ($config['enabled'] ?? ($this->encryptService->isEnabled() ? 1 : 0)), 'scope' => (string) ($config['scope'] ?? $this->encryptService->getScope()), 'key_version' => (string) ($config['key_version'] ?? $this->encryptService->getKeyVersion()), 'timestamp_tolerance' => (int) ($config['timestamp_tolerance'] ?? 300), 'exclude_paths' => $config['exclude_paths'] ?? [], 'encrypted_paths' => $config['encrypted_paths'] ?? $this->encryptService->getEncryptedPaths(), 'public_key_path' => (string) ($config['public_key_path'] ?? ''), 'private_key_path' => (string) ($config['private_key_path'] ?? ''), 'public_key' => $this->encryptService->getPublicKey(), 'private_key' => $this->encryptService->getPrivateKey(), ]); } #[OA\Post(path: '/system/api-encrypt/generate-keypair', summary: '生成接口加密密钥对', tags: ['系统配置'])] #[Permission(code: 'system:config:update')] #[DataResponse(description: '生成成功')] public function generateKeypair(Request $request): Response { try { $keys = $this->encryptService->generateKeyPair(); $this->encryptService->persistKeyPair($keys); return Json::success('生成成功', [ 'public_key' => $this->encryptService->getPublicKey(), 'private_key' => $this->encryptService->getPrivateKey(), ]); } catch (\Throwable $exception) { return Json::fail($exception->getMessage()); } } }