我从2006年继承了一个旧的java项目(原来的dev早已不复存在,我之前从未编写过Java),我收到此错误:
EncryptionException:javax.crypto.IllegalBlockSizeException:使用填充密码解密时,输入长度必须是8的倍数
它引用的代码如下所示:
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 );
}
}
Run Code Online (Sandbox Code Playgroud)
我不完全确定程序的内部工作方式,但我知道在这个项目目录中有一些配置文件和一个key.properties文件.就"输入长度"而言(如错误消息所指),我的数据库密码长度为15个字符,key.properties中的"密钥"长度为25个字符.我不知道这是否重要.
注意事项: