7.8
15832144755
2021-07-08 2080267e3245f0df9efc621c279922dc5ebb7c8e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.hxzkoa.tools;
 
import java.util.Properties;
 
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
 
import com.hxzkoa.util.DESUtil;
 
public class EncryptablePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {  
       public static String key = "FHGT4KHVJKVKV2KHCTBM";
       public static String keySafe;
  
    protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)  
        throws BeansException {  
            try {  
                keySafe=props.getProperty("key.safe")==null?"0":props.getProperty("key.safe"); 
                  String username = props.getProperty("jdbc.username");  
                  if (username != null) {  
                    props.setProperty("jdbc.username", DESUtil.decrypt(username,key));  
                    System.out.println(props.getProperty("jdbc.username"));
                  }  
                    
                  String password = props.getProperty("jdbc.password");  
                  if (password != null) {  
                    props.setProperty("jdbc.password", DESUtil.decrypt(password,key)); 
                  }  
                    
                  String url = props.getProperty("jdbc.url");  
                  if (url != null) {  
                    props.setProperty("jdbc.url",DESUtil.decrypt( url,key)); 
                  }  
                super.processProperties(beanFactory, props);  
            } catch (Exception e) {  
                e.printStackTrace();  
                throw new BeanInitializationException(e.getMessage());  
            }  
        } 
}