Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring JDBC模板-解密密码_Java_Spring_Encryption_Jdbc - Fatal编程技术网

Java Spring JDBC模板-解密密码

Java Spring JDBC模板-解密密码,java,spring,encryption,jdbc,Java,Spring,Encryption,Jdbc,我正在使用SpringJDBC模板建立与数据库的连接。密码是加密格式的,希望在JDBC模板的帮助下对其进行解密。为了实现相同的功能,我知道我必须重写DriverManager数据源。我尝试实现相同的功能,但没有成功 <bean id="dataSource" class="MyclassName"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <pro

我正在使用SpringJDBC模板建立与数据库的连接。密码是加密格式的,希望在JDBC模板的帮助下对其进行解密。为了实现相同的功能,我知道我必须重写DriverManager数据源。我尝试实现相同的功能,但没有成功

<bean id="dataSource"
    class="MyclassName">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource"></property>
</bean>
}

我知道我必须更改我自己编写的,每当需要替换变量时就会调用它

jdbc.password={base64}yourEncryptedSecret

import java.io.IOException;
import sun.misc.BASE64Decoder;
public class PropertyPlaceholderConfigurer
  extends org.springframework.beans.factory.config.PropertyPlaceholderConfigurer {

  @Override
  protected String convertPropertyValue(final String originalValue) {
    String cryptString = "{base64}";
    if (originalValue.startsWith(cryptString)) {
      BASE64Decoder decoder = new BASE64Decoder();
      String decodedPassword = null;
      try {
        decodedPassword = new String(decoder.decodeBuffer(originalValue.substring(cryptString.length())));
      } catch (IOException e) {
        e.printStackTrace();
      }
      return decodedPassword;
    }
    return originalValue;
  }
}

感谢您的帮助…我已经为我的应用程序实现了相同的功能。然而,我仍然想知道为什么问题中提出的方法不起作用。
import java.io.IOException;
import sun.misc.BASE64Decoder;
public class PropertyPlaceholderConfigurer
  extends org.springframework.beans.factory.config.PropertyPlaceholderConfigurer {

  @Override
  protected String convertPropertyValue(final String originalValue) {
    String cryptString = "{base64}";
    if (originalValue.startsWith(cryptString)) {
      BASE64Decoder decoder = new BASE64Decoder();
      String decodedPassword = null;
      try {
        decodedPassword = new String(decoder.decodeBuffer(originalValue.substring(cryptString.length())));
      } catch (IOException e) {
        e.printStackTrace();
      }
      return decodedPassword;
    }
    return originalValue;
  }
}