baomidou / dynamic-datasource

dynamic datasource for springboot 多数据源 动态数据源 主从分离 读写分离 分布式事务
https://www.kancloud.cn/tracy5546/dynamic-datasource/2264611
Apache License 2.0
4.76k stars 1.2k forks source link

数据库配置加密信息,自定义公私钥异常 #623

Closed joakapp closed 10 months ago

joakapp commented 10 months ago

Please fill it out carefully, or it will be closed. 请认真填写,不然会直接关闭。

Enviroment

JDK Version(required): 11.02

SpringBoot Version(required): 2.7.15

dynamic-datasource-spring-boot-starter Version(required):4.3.0

druid Version(optional):

Describe what happened

数据库配置用户名、密码、URL时通过加密进行处理,自定义公私钥,但是再解密的过程出现异常。

具体异常信息如下: 2024-01-29 08:57:34,710 ERROR [main] com.shun.test.TestDynamicService (TestDynamicService.java:93) - 异常信息 javax.crypto.BadPaddingException: Decryption error at sun.security.rsa.RSAPadding.unpadV15(RSAPadding.java:369) ~[?:?] at sun.security.rsa.RSAPadding.unpad(RSAPadding.java:282) ~[?:?] at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:362) ~[?:?] at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:405) ~[?:?] at javax.crypto.Cipher.doFinal(Cipher.java:2260) ~[?:?] at com.baomidou.dynamic.datasource.toolkit.CryptoUtils.decrypt(CryptoUtils.java:199) ~[dynamic-datasource-creator-4.3.0.jar:?] at com.baomidou.dynamic.datasource.toolkit.CryptoUtils.decrypt(CryptoUtils.java:71) ~[dynamic-datasource-creator-4.3.0.jar:?] at com.shun.test.TestDynamicService.testDyDecrypt(TestDynamicService.java:89) ~[test-classes/:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]

其中加密的明文为:root。

在没有使用分组加解密的版本,能够正常进行加解密。请老师帮忙看一下。

If there is an exception,or aop invalid,please attach the exception trace:

Just paste your stack trace here!

Steps to reproduce

joakapp commented 10 months ago

密钥模(modulus )长度 只能设置512位,超过即会报错

huayanYu commented 10 months ago

看文档,自定义加密解密

joakapp commented 10 months ago

感谢,但是代码中确实存在这个问题。和自定义加解密无关。

huayanYu commented 10 months ago

感谢,但是代码中确实存在这个问题。和自定义加解密无关。

我抄的druid的,我不懂加解密。