欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Input length must be multiple of 8 when decrypting with padded cipher 错误

程序员文章站 2022-07-10 15:25:20
...

一、问题描述

用TrueLicense 做了个授权的功能,将生成的证书文件,导入到程序里,一启动就报如下错:

javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
	at com.sun.crypto.provider.CipherCore.prepareInputBuffer(CipherCore.java:1005)
	at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:848)
	at com.sun.crypto.provider.PBES1Core.doFinal(PBES1Core.java:423)
	at com.sun.crypto.provider.PBEWithMD5AndDESCipher.engineDoFinal(PBEWithMD5AndDESCipher.java:316)
	at javax.crypto.Cipher.doFinal(Cipher.java:2164)
	at de.schlichtherle.license.PrivacyGuard.key2cert(PrivacyGuard.java:169)

二、解决方法

报这个错误,基本上就是你的密文有问题,仔细检查下,看是否被转义啥的,我这用的是文件,刚开始没注意

Input length must be multiple of 8 when decrypting with padded cipher 错误
debug了下,也没发现啥问题,搞了半天,最后发现还是这个文件的原因引起的,醉了。。。在resources目录下的文件是1kb,打包之后在classes目录下却变成了2kb…这明显是被修改了

Input length must be multiple of 8 when decrypting with padded cipher 错误
肯定是maven引起的,通过如下插件,即可过滤掉该文件,让maven不对该文件做任何处理

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-resources</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/classes</outputDirectory>
                            <useDefaultDelimiters>true</useDefaultDelimiters>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/main/resources</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                            <nonFilteredFileExtensions>
                                <!-- xxx文件后缀名,不被filter打包时编码 -->
                                <nonFilteredFileExtension>lic</nonFilteredFileExtension>
                                <nonFilteredFileExtension>keystore</nonFilteredFileExtension>
                            </nonFilteredFileExtensions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

相关标签: JAVA java maven