Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取javax.crypto.IllegalBlockSizeException:解密错误中的最后一个块未完成_Java_Swing_Encryption_Netbeans_Public Key Encryption - Fatal编程技术网

获取javax.crypto.IllegalBlockSizeException:解密错误中的最后一个块未完成

获取javax.crypto.IllegalBlockSizeException:解密错误中的最后一个块未完成,java,swing,encryption,netbeans,public-key-encryption,Java,Swing,Encryption,Netbeans,Public Key Encryption,我是java新手,请原谅我的愚蠢问题 1) 我的项目从netbeans 6移动到了8 2) jdk从6u45移动到8u11 3) 调试时成功安装到新环境后 获取错误:javax.crypto.IllegalBlockSizeException:最后一个块 解密不完全 堆栈跟踪: com.alstom.tsoft.controller.system.ParameterTablesController$LoadOfflineWorker -[javax.crypto.CipherInputStrea

我是java新手,请原谅我的愚蠢问题

1) 我的项目从netbeans 6移动到了8

2) jdk从6u45移动到8u11

3) 调试时成功安装到新环境后

获取错误:javax.crypto.IllegalBlockSizeException:最后一个块 解密不完全

堆栈跟踪:

com.alstom.tsoft.controller.system.ParameterTablesController$LoadOfflineWorker -[javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:121), javax.crypto.cipheriputstream.read(cipheriputstream.java:192), com.alstom.tsoft.crypto.CryptoManager.DecryptoString(CryptoManager.java:146), com.alstom.tsoft.io.CryptedFieldReader.readField(CryptedFieldReader.java:58)

4) 这在以前的
环境(jdk6和netbeans6)
中从未发生过,这是项目中唯一的变化

我们正在使用以下输入:

private static final String ALGO_TYPE = "AES";
private static final String ALGO_FULL_NAME = "AES/ECB/PKCS5Padding";
private static final String ALGO_PROVIDER = "BC";

public String encryptString(String input) throws NoSuchAlgorithmException,NoSuchProviderException,
       NoSuchPaddingException,InvalidKeyException,IOException {
    StringBuffer output = new StringBuffer();
    CipherInputStream cis = new CipherInputStream(
           new ByteArrayInputStream(input.getBytes()),
           getEncryptionCipher());                
    int b;
    while ( ( b = cis.read() ) != -1 ) {           
       String twoHexDigit = String.format("%1$02x",b);           
       //m_logger.info(":"+b+":"+twoHexDigit.toUpperCase());
       output.append(twoHexDigit.toUpperCase());
    }
    return output.toString();
}
//Dencryption
public String decryptString(String input) throws NoSuchAlgorithmException,NoSuchProviderException,
       NoSuchPaddingException,InvalidKeyException,IOException {       
    StringBuffer output = new StringBuffer();                        
    byte[] inputBytes = convertHexStringToByte(input);        

    CipherInputStream cis = new CipherInputStream(
           new ByteArrayInputStream(inputBytes), 
           getDecryptionCipher());                      
    int b;
    while ( ( b = cis.read() ) != -1 ) {
       output.append(new Character((char)b));
    }                                              
    return output.toString();
}
请建议我哪里做错了以及如何调试


提前感谢

您可能需要添加Java加密扩展(JCE)JRE对你的力量是无限的。在这里下载:两个JAR都已经存在。当我创建.exe并运行throughFirst修复你的流处理时,这个错误发生了,使用try with resources。这个异常可能总是发生,但是
CipherInputStream
具有“秘密”洗牌异常的恼人特性(即捕捉它们,然后忽略它们)。谢谢您的评论Maarten,但它已经在调用函数中处理过了,请您建议使用什么来代替CipherInputStream。我了解到,在jdk从32位切换到64位也会产生问题,而CipherInputStream的使用有时也会产生问题?有人有类似的问题吗