Java加密扩展(JCE)无限强度随机失败

Java加密扩展(JCE)无限强度随机失败,java,cryptography,jce,Java,Cryptography,Jce,我在Java中面临一个相当奇怪的解密行为。使用下面的代码 public void decrypt(File file, String output_file_path) throws FileNotFoundException, IOException, GeneralSecurityException { String hex_enc_key = "346a23652a46392b4d73257c67317e352e3372482177652c"; Cipher cipher

我在Java中面临一个相当奇怪的解密行为。使用下面的代码

public void decrypt(File file, String output_file_path) throws FileNotFoundException, IOException, GeneralSecurityException {
    String hex_enc_key = "346a23652a46392b4d73257c67317e352e3372482177652c";
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
    SecretKeySpec keySpec = new SecretKeySpec(HexParser.fromHexString(hex_enc_key), "AES");
    cipher.init(Cipher.DECRYPT_MODE, keySpec);
    CipherOutputStream cos = new CipherOutputStream(new FileOutputStream(new File(output_file_path)), cipher);
    FileInputStream fis = new FileInputStream(file);
    doCopy(fis, cos);
}
我有随机的例外

java.security.InvalidKeyException:密钥大小或默认参数非法

我在谷歌上搜索了这个问题并发现了,但我不明白为什么我会得到这些随机异常,即使我总是使用相同的密钥(根据需要解密的输入文件,有时有效,有时无效)

为了清楚起见,我正在使用

Cipher.getMaxAllowedKeyLength("AES")
要检查JCE限制,并且使用相同设置进行加密没有任何问题,请执行以下操作:

public void encrypt(File file, String output_file_path) throws FileNotFoundException, IOException, GeneralSecurityException {
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); 
    SecretKeySpec keySpec = new SecretKeySpec(HexParser.fromHexString(db_enc_key), "AES");
    cipher.init(Cipher.ENCRYPT_MODE, keySpec);
    CipherInputStream cis = new CipherInputStream(new FileInputStream(file), cipher);
    FileOutputStream os = new FileOutputStream(new File(output_file_path));
    doCopy(cis, os);
    cis.close();
    os.close();
}
谁能给我指出正确的方向吗


非常感谢,nicola

ECB模式不安全。你在多台计算机上运行这个吗?@SLaks:这是第三方应用(whatsapp)的概念证明,所以我不能更改encryption@Antimony:是的,这是我的目标,否则我将解决在服务器上安装JCE的问题…您是否在某些计算机上而不是在其他计算机上持续出现此异常?