开发者社区> 问答> 正文

加密报错 DerInputStream.getLength(): lengthTag=105, to

加密后运行,报一下错误,请问是怎么处理?

Caused by: java.lang.IllegalArgumentException: Failed to decrypt. at com.alibaba.druid.filter.config.ConfigFilter.decrypt(ConfigFilter.java:211) at com.alibaba.druid.filter.config.ConfigFilter.init(ConfigFilter.java:123) at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:643) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1060) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1056) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:104) at com.baomidou.mybatisplus.entity.GlobalConfiguration.setMetaData(GlobalConfiguration.java:255) at com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean.buildSqlSessionFactory(MybatisSqlSessionFactoryBean.java:530) at com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean.afterPropertiesSet(MybatisSqlSessionFactoryBean.java:387) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ... 53 common frames omitted Caused by: java.lang.IllegalArgumentException: Failed to get public key at com.alibaba.druid.filter.config.ConfigTools.getPublicKey(ConfigTools.java:101) at com.alibaba.druid.filter.config.ConfigFilter.getPublicKey(ConfigFilter.java:229) at com.alibaba.druid.filter.config.ConfigFilter.decrypt(ConfigFilter.java:201) ... 63 common frames omitted Caused by: java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: DerInputStream.getLength(): lengthTag=105, too big. at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(Unknown Source) at java.security.KeyFactory.generatePublic(Unknown Source) at com.alibaba.druid.filter.config.ConfigTools.getPublicKey(ConfigTools.java:99) ... 65 common frames omitted Caused by: java.security.InvalidKeyException: IOException: DerInputStream.getLength(): lengthTag=105, too big. at sun.security.x509.X509Key.decode(Unknown Source) at sun.security.x509.X509Key.decode(Unknown Source) at sun.security.rsa.RSAPublicKeyImpl.(Unknown Source) at sun.security.rsa.RSAKeyFactory.generatePublic(Unknown Source) ... 68 common frames omitted

原提问者GitHub用户maxiaoxian

展开
收起
山海行 2023-07-05 20:59:10 730 0
3 条回答
写回答
取消 提交回答
  • 根据你提供的错误信息,这个错误可能是由于加密过程中出现了一些配置错误导致的。

    具体地说,java.lang.IllegalArgumentException: Failed to decrypt 表示解密失败,而 java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: DerInputStream.getLength(): lengthTag=105, too big. 表示在获取公钥时出现了异常。

    以下是一些可能的解决方案:

    1. 检查公钥和私钥是否匹配。确保使用正确的公钥来解密数据,并与实际使用的私钥相匹配。

    2. 检查加密输入数据的长度。如果明文数据的长度超过了RSA公钥的长度,可以考虑使用对称加密算法(例如AES)或将数据分成较小的块进行分段加密。

    3. 确认加密输入数据的编码方式。请检查您使用的编码方式(例如Base64编码或Hex编码),并确保正确地对明文数据进行编码。

    4. 如果你使用的是自定义的加密配置,检查加密配置参数是否正确设置,并确认没有遗漏或错误设置任何必要的配置项。

    2023-07-30 14:36:28
    赞同 展开评论 打赏
  • 北京阿里云ACE会长

    如果您在进行加密操作时出现“DerInputStream.getLength(): lengthTag=105, too big”的错误,可能是因为您的加密输入数据长度过长,超出了ASN.1编码规定的范围。这个错误通常出现在使用RSA公钥加密时,明文的长度超过了RSA公钥的长度。以下是一些可能的解决方案:

    检查加密输入数据的长度。请检查您要加密的数据长度是否超过了RSA公钥的长度,如果超过了RSA公钥的长度,可以考虑使用对称加密算法,例如AES等。

    使用正确的编码方式。在进行加密操作时,需要将明文数据编码为二进制格式。请确保使用了正确的编码方式,例如Base64编码或Hex编码。

    检查加密算法。不同的加密算法支持的数据长度可能不同。请确保您选择的加密算法支持您要加密的数据长度。例如,如果您要加密的数据长度超过了RSA公钥的长度,可以使用分段加密的方式,将数据分成多个较小的块进行加密。

    使用正确的密钥。请确认您使用的RSA公钥是否正确,并且与实际使用的私钥匹配。

    2023-07-30 13:06:16
    赞同 展开评论 打赏
  • 配置错误

    原回答者GitHub用户maxiaoxian

    2023-07-06 11:53:25
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
基于可信计算与加密计算 打造云上原生计算安全 立即下载
\"视频服务特色解决方案——直播连麦与点播加密 \" 立即下载
量子加密通信技术 立即下载