@Override
    public void doFilter(IConfigRequest request, IConfigResponse response, IConfigFilterChain filterChain)
            throws NacosException {
        if (Objects.nonNull(request) && request instanceof ConfigRequest && Objects.isNull(response)) {
            
            // Publish configuration, encrypt
            ConfigRequest configRequest = (ConfigRequest) request;
            String dataId = configRequest.getDataId();
            String content = configRequest.getContent();
            
            Pair<String, String> pair = EncryptionHandler.encryptHandler(dataId, content);
            String secretKey = pair.getFirst();
            String encryptContent = pair.getSecond();
            if (!StringUtils.isBlank(encryptContent) && !encryptContent.equals(content)) {
                ((ConfigRequest) request).setContent(encryptContent);
            }
            if (!StringUtils.isBlank(secretKey) && !secretKey.equals(((ConfigRequest) request).getEncryptedDataKey())) {
                ((ConfigRequest) request).setEncryptedDataKey(secretKey);
            } else if (StringUtils.isBlank(((ConfigRequest) request).getEncryptedDataKey()) && StringUtils.isBlank(secretKey)) {
                ((ConfigRequest) request).setEncryptedDataKey("");
            }
        }
        if (Objects.nonNull(response) && response instanceof ConfigResponse && Objects.isNull(request)) {
            
            // Get configuration, decrypt
            ConfigResponse configResponse = (ConfigResponse) response;
            
            String dataId = configResponse.getDataId();
            String encryptedDataKey = configResponse.getEncryptedDataKey();
            String content = configResponse.getContent();
            
            Pair<String, String> pair = EncryptionHandler.decryptHandler(dataId, encryptedDataKey, content);
            String secretKey = pair.getFirst();
            String decryptContent = pair.getSecond();
            if (!StringUtils.isBlank(decryptContent) && !decryptContent.equals(content)) {
                ((ConfigResponse) response).setContent(decryptContent);
            }
            if (!StringUtils.isBlank(secretKey) && !secretKey.equals(((ConfigResponse) response).getEncryptedDataKey())) {
                ((ConfigResponse) response).setEncryptedDataKey(secretKey);
            } else if (StringUtils.isBlank(((ConfigResponse) response).getEncryptedDataKey()) && StringUtils.isBlank(secretKey)) {
                ((ConfigResponse) response).setEncryptedDataKey("");
            }
        }
        filterChain.doFilter(request, response);
    }
@Test
    void doFilter() throws NacosException {
        Mockito.when(configRequest.getDataId()).thenReturn("cipher-aes-test");
        Mockito.when(configRequest.getContent()).thenReturn("nacos");
        
        configEncryptionFilter.doFilter(configRequest, null, iConfigFilterChain);
        
        Mockito.verify(configRequest, Mockito.atLeast(1)).getDataId();
        Mockito.verify(configRequest, Mockito.atLeast(1)).getContent();
        
        Mockito.when(configResponse.getDataId()).thenReturn("test-dataid");
        Mockito.when(configResponse.getContent()).thenReturn("nacos");
        Mockito.when(configResponse.getEncryptedDataKey()).thenReturn("1234567890");
        
        configEncryptionFilter.doFilter(null, configResponse, iConfigFilterChain);
        
        Mockito.verify(configResponse, Mockito.atLeast(1)).getDataId();
        Mockito.verify(configResponse, Mockito.atLeast(1)).getContent();
        Mockito.verify(configResponse, Mockito.atLeast(1)).getEncryptedDataKey();
    }