NutzCN Logo
问答 druid 密码加密的问题
发布于 2002天前 作者 jirongjun 3309 次浏览 复制 上一个帖子 下一个帖子
标签:

NB 2.3.5.v20190516
druid 1.1.16
通过java -cp druid.jar生成了密码,然后在application.properties中设置了

jdbc.password=FReHTSA23pFd6TPNpW1ovMJ6QHVm3+pY7G7v/92jTveCIdONDUuD52iNvQRjhembrp1qBlUSAxuR3eYh2zaTdg==
jdbc.connectionProperties=config.decrypt=true;config.decrypt.key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIC1hSMkyUd6an+ShA4b1/jC+jF6Y7eDaHRGQsy7bCEzcs3ddda2nKoehFTKCCfTxOpBXZRf9b0pfiI944Hw0BMCAwEAAQ==
jdbc.filters=mergeStat,wall,config

启动的时候报错

2019-06-29 10:36:08,882 [main] [com.alibaba.druid.pool.DruidDataSource] - {dataSource-2} init error
java.lang.IllegalArgumentException: Failed to decrypt.
	at com.alibaba.druid.filter.config.ConfigFilter.decrypt(ConfigFilter.java:205)
	at com.alibaba.druid.filter.config.ConfigFilter.init(ConfigFilter.java:123)
	at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:827)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1311)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1307)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:109)
	at org.nutz.trans.Trans.getConnectionAuto(Trans.java:263)
.........

Caused by: org.nutz.lang.InvokingException: Fail to invoke [org.nutz.boot.starter.nutz.dao.NutDaoStarter].getDao() by args:
 {
	CreateTime:"2019-06-29 10:36:08",
	ActiveCount:0,
	PoolingCount:0,
	CreateCount:0,
	DestroyCount:0,
	CloseCount:0,
	ConnectCount:0,
	Connections:[
	]
}
org.nutz.dao.impl.FileSqlManager@771a660
For the reason: Decryption error
	at org.nutz.lang.Invoking.invoke(Invoking.java:195)
	at org.nutz.lang.Mirror.invoke(Mirror.java:1135)
	at org.nutz.ioc.impl.ObjectMakerImpl$1.born(ObjectMakerImpl.java:80)
	at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:78)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:117)
	... 11 more
Caused by: javax.crypto.BadPaddingException: Decryption error
	at sun.security.rsa.RSAPadding.unpadV15(Unknown Source)
	at sun.security.rsa.RSAPadding.unpad(Unknown Source)
	at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:356)
	at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:389)
	at javax.crypto.Cipher.doFinal(Cipher.java:2164)
	at com.alibaba.druid.filter.config.ConfigTools.decrypt(ConfigTools.java:151)
	at com.alibaba.druid.filter.config.ConfigFilter.decrypt(ConfigFilter.java:197)
	at com.alibaba.druid.filter.config.ConfigFilter.init(ConfigFilter.java:123)
	at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:827)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1311)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1307)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:109)
	at org.nutz.trans.Trans.getConnectionAuto(Trans.java:263)
	at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:106)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:189)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:180)
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:108)
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:112)
	at org.nutz.boot.starter.nutz.dao.NutDaoStarter.getDao(NutDaoStarter.java:165)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.lang.Invoking$DefaultInvoker.invoke(Invoking.java:47)
	at org.nutz.lang.Invoking.invoke(Invoking.java:192)

5 回复

debug看看DruidDataSource的setPassword传入的是不是你想要的值

配置的值都是正确的,在ConfigFilter.class的197报错
String passwordPlainText = ConfigTools.decrypt(publicKey, encryptedPassword);
然后,在ConfigTools.class的151行报错
byte[] plainBytes = cipher.doFinal(cipherBytes);
JDK1.8

恩,晚上试试

jdbc.password=FReHTSA23pFd6TPNpW1ovMJ6QHVm3+pY7G7v/92jTveCIdONDUuD52iNvQRjhembrp1qBlUSAxuR3eYh2zaTdg==
jdbc.connectionProperties=config.decrypt=true;config.decrypt.key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIC1hSMkyUd6an+ShA4b1/jC+jF6Y7eDaHRGQsy7bCEzcs3ddda2nKoehFTKCCfTxOpBXZRf9b0pfiI944Hw0BMCAwEAAQ==
jdbc.filters=config

大意了,我自己把decrypt拼写错了。

添加回复
请先登陆
回到顶部