EncryptionException:javax.crypto。当使用padd密码解密时,输入长度必须是8的倍数。

时间:2021-11-09 18:31:12

I have inherited an old java project from 2006 (the original dev is long gone, and I've never coded Java before) where I am getting this error:

我从2006年继承了一个旧的java项目(原来的dev已经没有了,而且我以前从来没有编写过java代码),在那里我得到了这个错误:

EncryptionException: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher

EncryptionException:javax.crypto。当使用padd密码解密时,输入长度必须是8的倍数。

The code it references looks like this:

它引用的代码如下:

public String decrypt( String encryptedString ) throws EncryptionException
{
    if ( encryptedString == null || encryptedString.trim().length() <= 0 )
            throw new IllegalArgumentException( "encrypted string was null or empty" );

    try
    {
        SecretKey key = keyFactory.generateSecret( keySpec );
        cipher.init( Cipher.DECRYPT_MODE, key );
        BASE64Decoder base64decoder = new BASE64Decoder();
        byte[] cleartext = base64decoder.decodeBuffer( encryptedString );
        byte[] ciphertext = cipher.doFinal( cleartext );

        return bytes2String( ciphertext );
    }
    catch (Exception e)
    {
        throw new EncryptionException( e );
    }
}

I'm not entirely sure of the inner workings of the program, but I do know that in this project directory are a few config files, and a key.properties file. As far as "Input Lengths" go (as the error message refers to), my the password for the database is 15 chars long, and the "key" in key.properties is 25 chars long. I have no idea if that matters or not.

我不完全确定程序的内部工作方式,但我知道在这个项目目录中有一些配置文件和一个密钥。属性文件。至于“输入长度”go(错误消息指的是),我的数据库密码是15个字符长,关键字是“key”。属性是25个字符长。我不知道这是否重要。

Things to note:

注意事项:

  • I have tried changing the DB password to 16 chars (a multiple of 8) but to no avail.
  • 我试过将DB密码更改为16个字符(8个倍数),但没有效果。
  • I have read this and this and they have not helped
  • 我读过这篇文章,但他们没有帮助。
  • I am moving this project from one server to another. It works on its original server.
  • 我正在把这个项目从一个服务器转移到另一个服务器。它在原来的服务器上运行。
  • The original server runs JRE 1.4.2. The new server runs JRE 1.6u27.
  • 原始服务器运行JRE 1.4.2。新服务器运行JRE 1.6u27。
  • I REALLY don't want to have to rebuild the .jar. I am not a java developer and the project is pretty massive.
  • 我真的不想重建这个。jar。我不是java开发人员,这个项目非常庞大。

Thanks for all your help.

谢谢你的帮助。

2 个解决方案

#1


5  

The input to which the error message refers is the cipher text (oddly-named cleartext), the result of the Base-64 decoding operation. Make sure that the encryptedString you are passing to this method decodes to a byte array with length that is a multiple of 8.

错误消息所引用的输入是密码文本(非常命名的明文),是Base-64解码操作的结果。确保您传递给该方法的encryptedString对一个长度为8的字节数组进行解码。

#2


1  

You should probably not change the JRE version unless you want to re-examine the code. I would try downgrading your JRE version on the new server before anything else, especially since the code previously worked.

您可能不应该更改JRE版本,除非您想重新检查代码。我将尝试在新服务器上降级您的JRE版本,尤其是在之前的代码工作之后。

#1


5  

The input to which the error message refers is the cipher text (oddly-named cleartext), the result of the Base-64 decoding operation. Make sure that the encryptedString you are passing to this method decodes to a byte array with length that is a multiple of 8.

错误消息所引用的输入是密码文本(非常命名的明文),是Base-64解码操作的结果。确保您传递给该方法的encryptedString对一个长度为8的字节数组进行解码。

#2


1  

You should probably not change the JRE version unless you want to re-examine the code. I would try downgrading your JRE version on the new server before anything else, especially since the code previously worked.

您可能不应该更改JRE版本,除非您想重新检查代码。我将尝试在新服务器上降级您的JRE版本,尤其是在之前的代码工作之后。