【发布时间】:2018-12-14 04:56:15
【问题描述】:
当我使用命令行工具openssl解密文件时,通过以下命令就可以了。
我没有关于加密的任何信息,客户端只提供以下命令和密钥。
openssl enc -d -aes-256-cbc -in 8MP_2018_12_12.gz.enc -out 8MP_2018_12_12.gz.enc.gz -pass file:pass.txt
我已经在 stackoverflow 中检查了很多问题,测试并运行了很多程序。因为我只提供了密钥,所以我不能使用ivparameterspec。
在 pass.txt 中,有一个提供的密钥
xxxxxxx12354125222sdsf <- example
我的程序
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.ssl.OpenSSL;
public class OpenSSLTest {
public static void main(String[] args) throws Exception {
File inputFile = new File("D:\\temp\\8MP_2018_12_12.gz.enc");
File outputFile = new File("D:\\temp\\8MP_2018_12_12.gz");
FileInputStream inputStream = new FileInputStream(inputFile);
InputStream in = OpenSSL.decrypt("aes-256-cbc", "xxxxxxx12354125222sdsf".toCharArray(), inputStream);
FileOutputStream outputStream = new FileOutputStream(outputFile);
IOUtils.copy(in, outputStream);
outputStream.flush();
outputStream.close();
in.close();
}
}
当我运行上面的程序时,我收到以下消息
Exception in thread "main" java.security.InvalidKeyException: Illegal key size
at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1039)
at javax.crypto.Cipher.implInit(Cipher.java:805)
at javax.crypto.Cipher.chooseProvider(Cipher.java:864)
at javax.crypto.Cipher.init(Cipher.java:1396)
at javax.crypto.Cipher.init(Cipher.java:1327)
at org.apache.commons.ssl.PKCS8Key.generateCipher(PKCS8Key.java:420)
at org.apache.commons.ssl.OpenSSL.decrypt(OpenSSL.java:165)
at OpenSSLTest.main(OpenSSLTest.java:15)
我已经尝试根据Java Security: Illegal key size or default parameters?修复该问题
我已经下载了jce_policy-8.zip。我已经将local_policy.jar 和US_export_policy.jar 放入我的....\jre1.8.0_66\lib\security 目录中。
我仍然收到上述错误消息。我的JDK版本是jdk1.8.0_66。
【问题讨论】:
标签: java encryption openssl