spring*.xml 프로필 명문 암호 화 실현

설명:고객 이 spring*.xml 에서 Oracle/Redis/MongoDB 의 IP,포트,사용자 이름,비밀 번 호 를 명문 으로 저장 할 수 없다 고 요구 합 니 다.수 요 를 받 은 저 는 어 쩔 수 없 었 지만 억지로 했 습 니 다.
시스템 구조:spring+mvc(Oracle 은 jdbc 로 자체 포 장 된 인터페이스)
1.데이터베이스 프로필 암호 화
원본 xml 설정

<?xml version="1.0" encoding="utf-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
 default-autowire="byType">
  
<context:component-scan base-package="cn.geoff" use-default-filters="false">
 <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
 </context:component-scan>

 <!-- Database Connection Pool -->
 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
 <property name="url" value="jdbc:oracle:thin:@192.168.100.100:1521:orcl"/>
 <property name="username" value="Geoff"/>
 <property name="password" value="123456"/>
 <property name="validationQuery" value="select 'x' from dual"/>

 .....
 </bean>

 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
 <property name="dataSource" ref="dataSource"/>
 </bean>
  
  </beans>

암호 화 실현 과정
사고방식:DruidDataSource 를 계승 하여 set 값 을 초기 화 할 때 복호화 합 니 다

/**
 *        
 * @author: Geoff
 * @create: 2020-12-30 16:46
 **/
public class DataBaseXml extends DruidDataSource {


  /**
   * Log4j logger
   */
  private final static Logger lg = LoggerFactory.getLogger(DataBaseXml.class);

  @Override
  public String getUrl() {
    return this.jdbcUrl;
  }

  @Override
  public void setUrl(String jdbcUrl) {
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("   【jdbcUrl】       ...");
      try {
        jdbcUrl = Encryption.decrypt(jdbcUrl, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("   【jdbcUrl】      ...");
        e.printStackTrace();
      }
    }
    this.jdbcUrl = jdbcUrl;
  }

  @Override
  public String getUsername() {
    return this.username;
  }

  @Override
  public void setUsername(String username) {
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("   【username】       ...");
      try {
        username = Encryption.decrypt(username, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("   【username】      ...");
        e.printStackTrace();
      }
    }
    this.username = username;
  }

  @Override
  public String getPassword() {
    return this.password;
  }

  @Override
  public void setPassword(String password) {
    if(GEOFF.DATA_BASE_IS_ENCRYPTION){
      lg.info("   【password】       ...");
      try {
        password = Encryption.decrypt(password, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("   【password】      ...");
        e.printStackTrace();
      }
    }
    this.password = password;
  }



}

수정 후 프로필

<?xml version="1.0" encoding="utf-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
 default-autowire="byType">
  
<context:component-scan base-package="cn.GEOFF" use-default-filters="false">
 <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
 </context:component-scan>

 <bean id="dataSource" class="cn.GEOFF.framework.core.DataBaseXml" init-method="init" destroy-method="close">
 <property name="url" value="4lZ4l804zIDqOJ5Wt3VNVLZvSLSDqCuQwhg5cAbQ1VG/vx+x+pEJQ6VJmLPO+PKK"/>
 <property name="username" value="PFEz8V4uvb06KhQxCLvLNA=="/>
 <property name="password" value="mMckYd6C5fo="/>
 <property name="validationQuery" value="select 'x' from dual"/>

 
 .....
 </bean>

 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
 <property name="dataSource" ref="dataSource"/>
 </bean>
  
  </beans>

2.Redis 프로필 암호 화
원본 프로필

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<!-- Jedis -->
<beans default-autowire="byName">

 <!-- Default Pool Config -->
 <bean id="defaultJedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
 <property name="maxTotal" value="5"/>
 <property name="maxIdle" value="2"/>
 <property name="minIdle" value="2"/>
 <property name="testOnBorrow" value="true"/>
 <property name="testOnReturn" value="true"/>
 <property name="testWhileIdle" value="true"/>
 </bean>


 <bean id="one" class="redis.clients.jedis.JedisPool" destroy-method="destroy">
    <constructor-arg index="0" ref="defaultJedisPoolConfig"/>
    <constructor-arg index="1" value="127.0.0.1" type="java.lang.String"/>
    <constructor-arg index="2" value="6379" type="int"/>
    <constructor-arg index="3" value="0" type="int"/>
    <constructor-arg index="4" value="123456" type="java.lang.String"/>
 </bean>


 <bean id="two" class="redis.clients.jedis.JedisPool" destroy-method="destroy">
    <constructor-arg index="0" ref="defaultJedisPoolConfig"/>
    <constructor-arg index="1" value="127.0.0.1" type="java.lang.String"/>
    <constructor-arg index="2" value="6379" type="int"/>
    <constructor-arg index="3" value="0" type="int"/>
    <constructor-arg index="4" value="123456" type="java.lang.String"/>
 </bean>


 <bean id="three" class="redis.clients.jedis.JedisPool" destroy-method="destroy">
    <constructor-arg index="0" ref="defaultJedisPoolConfig"/>
    <constructor-arg index="1" value="127.0.0.1" type="java.lang.String"/>
    <constructor-arg index="2" value="6379" type="int"/>
    <constructor-arg index="3" value="0" type="int"/>
    <constructor-arg index="4" value="123456" type="java.lang.String"/>
 </bean>
</beans>

암호 화 실현 사고:JedisPool 은 구조 함 수 를 사용 하여 만 들 었 기 때문에 JedisPool 을 계승 한 후에 JedisPool 구조 함 수 를 호출 할 때 static 복호화 방법 으로 복호화 합 니 다.

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.*;

/**
 * redis          
 * @author: Geoff
 * @create: 2020-12-30 17:20
 **/
public class JedisPoolXml extends JedisPool{


  /**
   * Log4j logger
   */
  private final static Logger lg = LoggerFactory.getLogger(JedisPoolXml.class);



  public JedisPoolXml(GenericObjectPoolConfig poolConfig, String host, String port, String timeout, String password) {
    super(poolConfig,decryptHost(host),decryptPort(port),decryptTimeout(timeout),decryptPassword(password), 0, (String)null);
  }

  private JedisPoolXml(GenericObjectPoolConfig poolConfig, String host, String port,String timeout, String password, String database){
    super(poolConfig,decryptHost(host),decryptPort(port),decryptTimeout(timeout),decryptPassword(password),decryptDatabase(database));
  }


  private static String decryptHost(String host){
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("Redis【host】       ...");
      try {
        host = Encryption.decrypt(host, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("Redis【host】      ...");
        e.printStackTrace();
      }
    }
    return host;
  }

  private static int decryptPort(String port){
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("Redis【port】       ...");
      try {
        port = Encryption.decrypt(port, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("Redis【port】      ...");
        e.printStackTrace();
      }
    }
    return Integer.parseInt(port);
  }

  private static int decryptTimeout(String timeout){
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("Redis【timeout】       ...");
      try {
        timeout = Encryption.decrypt(timeout, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("Redis【timeout】      ...");
        e.printStackTrace();
      }
    }
    return Integer.parseInt(timeout);
  }

  private static String decryptPassword(String password){
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("Redis【password】       ...");
      try {
        password = Encryption.decrypt(password, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("Redis【password】      ...");
        e.printStackTrace();
      }
    }
    return password;
  }

  private static int decryptDatabase(String database){
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("Redis【database】       ...");
      try {
        database = Encryption.decrypt(database, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("Redis【database】      ...");
        e.printStackTrace();
      }
    }
    return Integer.parseInt(database);
  }

}

수정 후 xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<!-- Jedis -->
<beans default-autowire="byName">

 <bean id="defaultJedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
 <property name="maxTotal" value="5"/>
 <property name="maxIdle" value="2"/>
 <property name="minIdle" value="2"/>
 <property name="testOnBorrow" value="true"/>
 <property name="testOnReturn" value="true"/>
 <property name="testWhileIdle" value="true"/>
 </bean>


 <bean id="one" class="cn.GEOFF.framework.core.JedisPoolXml" destroy-method="destroy">
 <constructor-arg index="0" ref="defaultJedisPoolConfig"/>
 <constructor-arg index="1" value="N98/M6A3acRnYMqIQEXGEg==" type="java.lang.String"/>
 <constructor-arg index="2" value="INDccYoGS/Y=" type="java.lang.String"/>
 <constructor-arg index="3" value="CXszBZysXWY=" type="java.lang.String"/>
 <constructor-arg index="4" value="mMckYd6C5fo=" type="java.lang.String"/>
 </bean>


 <bean id="two" class="cn.GEOFF.framework.core.JedisPoolXml" destroy-method="destroy">
 <constructor-arg index="0" ref="defaultJedisPoolConfig"/>
 <constructor-arg index="1" value="N98/M6A3acRnYMqIQEXGEg==" type="java.lang.String"/>
 <constructor-arg index="2" value="INDccYoGS/Y=" type="java.lang.String"/>
 <constructor-arg index="3" value="CXszBZysXWY=" type="java.lang.String"/>
 <constructor-arg index="4" value="mMckYd6C5fo=" type="java.lang.String"/>
 </bean>


 <bean id="three" class="cn.GEOFF.framework.core.JedisPoolXml" destroy-method="destroy">
 <constructor-arg index="0" ref="defaultJedisPoolConfig"/>
 <constructor-arg index="1" value="N98/M6A3acRnYMqIQEXGEg==" type="java.lang.String"/>
 <constructor-arg index="2" value="INDccYoGS/Y=" type="java.lang.String"/>
 <constructor-arg index="3" value="CXszBZysXWY=" type="java.lang.String"/>
 <constructor-arg index="4" value="mMckYd6C5fo=" type="java.lang.String"/>
 </bean>

</beans>

3.MongoDB 프로필 암호 화(spring-data-mognodb 프레임 워 크 사용)
원본 xml 설정

<?xml version="1.0" encoding="utf-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:mongo="http://www.springframework.org/schema/data/mongo"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">


 <mongo:mongo-client id="mongoClient" host="192.168.100.100" port="27017" credentials="jyzq_zsc:123456@JYZQ_ZSC">
 
 </mongo:mongo-client>

 <!-- Factory -->
 <mongo:db-factory id="mongoDbFactory" dbname="PFEz8V4uvb06KhQxCLvLNA==" mongo-ref="mongoClient"/>
 <mongo:db-factory id="mongoDbFactory" dbname="JYZQ_ZSC" mongo-ref="mongoClient"/>
 <mongo:mapping-converter id="converter" db-factory-ref="mongoDbFactory"/>


 <!-- Grid FS Template -->
 <bean id="gridFsTemplate" class="org.springframework.data.mongodb.gridfs.GridFsTemplate">
 <constructor-arg ref="mongoDbFactory"/>
 <constructor-arg ref="converter"/>
 </bean>


 <!-- Mongo Template -->
 <bean id="documentTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
 <constructor-arg ref="mongoDbFactory"/>
 <constructor-arg ref="converter"/>
 </bean>

</beans>

암호 화 사고:프로젝트 를 사용 할 때 bean 을 가 져 오 는 방식 으로 MongoTemplate 와 MongoDb Factory 를 가 져 오기 때문에 여러 가지 방법 으로 계승 한 후에 암호 화 를 시 도 했 지만 마지막 에는 안 됩 니 다.그 다음 에는 수 동 으로 만 초기 화 할 수 있 고 MongoTemplate 와 MongoDb Factory 를 bean 에 주입 할 수 있 습 니 다.

import com.mongodb.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.gridfs.GridFsTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Geoff
 * @create: 2020-12-31 16:15
 **/

@Configuration
public class MongoDBXml {

  /**
   * Log4j logger
   */
  private final static Logger lg = LoggerFactory.getLogger(MongoDBXml.class);

  private String host;
  private Integer port;
  private String userName;
  private String passWord;
  private String dataBase;

  private SimpleMongoDbFactory mongoDbFactory = null;
  private MappingMongoConverter converter = null;


  public String getHost() {
    return host;
  }


  public void setHost(String host) {
    this.host = decryptHost(host);
  }

  public Integer getPort() {
    return port;
  }


  public void setPort(String port) {
    this.port = decryptPort(port);
  }

  public String getUserName() {
    return userName;
  }

  public void setUserName(String userName) {
    this.userName = decryptUserName(userName);
  }

  public String getPassWord() {
    return passWord;
  }

  public void setPassWord(String passWord) {
    this.passWord = decryptPassword(passWord);
  }

  public String getDataBase() {
    return dataBase;
  }

  public void setDataBase(String dataBase) {
    this.dataBase = decryptDatabase(dataBase);
  }

  private String decryptHost(String host){
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("MongoDB【host】       ...");
      try {
        host = Encryption.decrypt(host, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("MongoDB【host】      ...");
        e.printStackTrace();
      }
    }
    return host;
  }

  private int decryptPort(String port){
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("MongoDB【port】       ...");
      try {
        port = Encryption.decrypt(port, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("MongoDB【port】      ...");
        e.printStackTrace();
      }
    }
    return Integer.parseInt(port);
  }

  private String decryptUserName(String userName){
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("MongoDB【userName】       ...");
      try {
        userName = Encryption.decrypt(userName, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("MongoDB【userName】      ...");
        e.printStackTrace();
      }
    }
    return userName;
  }

  private String decryptPassword(String passWord){
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("MongoDB【password】       ...");
      try {
        passWord = Encryption.decrypt(passWord, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("MongoDB【password】      ...");
        e.printStackTrace();
      }
    }
    return passWord;
  }

  private String decryptDatabase(String dataBase){
    if(GEOFF.DATA_BASE_IS_ENCRYPTION) {
      lg.info("MongoDB【database】       ...");
      try {
        dataBase = Encryption.decrypt(dataBase, GEOFF.DATA_BASE_ENCRYPTION_KEY);
      } catch (Exception e) {
        lg.error("MongoDB【database】      ...");
        e.printStackTrace();
      }
    }
    return dataBase;
  }




  public void init() {
    MongoClientOptions.Builder build = new MongoClientOptions.Builder();
    MongoClientOptions options = build.build();
    try {
      List<ServerAddress> addrs = new ArrayList<ServerAddress>();
      ServerAddress serverAddress = new ServerAddress(host, port);
      addrs.add(serverAddress);
      MongoCredential credential = MongoCredential.createScramSha1Credential(userName, dataBase, passWord.toCharArray());
      List<MongoCredential> credentials = new ArrayList<MongoCredential>();
      credentials.add(credential);
      MongoClient mongoClient = new MongoClient(addrs, credentials, options);
      mongoDbFactory = new SimpleMongoDbFactory(mongoClient, dataBase);
      DefaultDbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);
      MongoMappingContext mongoMappingContext = new MongoMappingContext();
      converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext);
      lg.info(" mongodb        ");
    } catch (Exception e) {
      lg.info(" mongodb        ");
      e.printStackTrace();
    }
    documentTemplate();
    gridFsTemplate();


  }

  @Bean
  public MongoTemplate documentTemplate() {
    if (mongoDbFactory != null && converter != null) {
      lg.info("MongoTemplate     ......");
      MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory, converter);
      return mongoTemplate;
    } else {
      lg.error("MongoTemplate     ......");
      return null;
    }
  }

  @Bean
  public GridFsTemplate gridFsTemplate() {
    if (mongoDbFactory != null && converter != null) {
      lg.info("GridFsTemplate     ......");
      GridFsTemplate gridFsTemplate = new GridFsTemplate(mongoDbFactory, converter);
      return gridFsTemplate;
    } else {
      lg.error("GridFsTemplate     ......");
      return null;
    }
  }

  public void destroy(){
    try {
      this.mongoDbFactory.destroy();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }


}

수정 후 프로필

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<!-- mongoDB -->
<beans>

 <bean id="mongoDBXml" class="cn.GEOFF.framework.core.MongoDBXml" init-method="init" destroy-method="destroy" >
 <property name="host" value="PpmNMR+X2UIVhG8gmNFFqg=="/>
 <property name="port" value="51QH8fifl1k="/>
 <property name="userName" value="yre5DufK9os6KhQxCLvLNA=="/>
 <property name="passWord" value="mMckYd6C5fo="/>
 <property name="dataBase" value="PFEz8V4uvb06KhQxCLvLNA=="/>
 </bean>

</beans>

4.마지막 으로 대응 하 는 복호화 클래스 를 첨부

import org.apache.commons.codec.binary.Base64;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.security.Key;
import java.security.SecureRandom;

/**
 *     token   
 *
 * @author: Geoff
 * @create: 2020-12-30 17:03
 **/

public class Encryption {
  //     
  public static final String KEY_ALGORITHM = "DES";
  //     /    /    
  // DES        -->>ECB:       、CBC:        、CFB:      、OFB:      
  public static final String CIPHER_ALGORITHM = "DES/ECB/PKCS5Padding";

  /**
   *     key  
   *
   * @param
   * @return     
   * @throws Exception
   */
  private static SecretKey keyGenerator(String keyStr) throws Exception {
    byte[] input = HexString2Bytes(keyStr);
    DESKeySpec desKey = new DESKeySpec(input);
    //         ,     DESKeySpec   
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(KEY_ALGORITHM);
    SecretKey securekey = keyFactory.generateSecret(desKey);
    return securekey;
  }


  /**
   *                
   */
  public static byte[] HexString2Bytes(String hexStr) {
    byte[] keyBytes = hexStr.getBytes();
    if (keyBytes.length == 16) {
      byte[] tmpKey = new byte[24];
      System.arraycopy(keyBytes, 0, tmpKey, 0, 16);
      System.arraycopy(keyBytes, 0, tmpKey, 16, 8);
      keyBytes = tmpKey;
    }
    return keyBytes;
  }

  /**
   *     
   *
   * @param data      
   * @param key   
   * @return       
   */
  public static String encrypt(String data, String key) throws Exception {
    Key deskey = keyGenerator(key);
    //    Cipher  ,            
    Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
    SecureRandom random = new SecureRandom();
    //    Cipher  ,       
    cipher.init(Cipher.ENCRYPT_MODE, deskey, random);
    byte[] results = cipher.doFinal(data.getBytes());
    //       。           Base64      
    return Base64.encodeBase64String(results);
  }

  /**
   *     
   *
   * @param data      
   * @param key   
   * @return       
   */
  public static String decrypt(String data, String key) throws Exception {
    Key deskey = keyGenerator(key);
    Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
    //    Cipher  ,       
    cipher.init(Cipher.DECRYPT_MODE, deskey);
    //       
    return new String(cipher.doFinal(Base64.decodeBase64(data)));
  }

}

spring*.xml 프로필 의 명문 암호 화 실현 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 spring*.xml 프로필 암호 화 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 많은 응원 바 랍 니 다!

좋은 웹페이지 즐겨찾기