我有一个在.Net
加密的文件。我必须在java
中解密该文件。
我在文本文件中有key
和IV
。此文件使用AES, CBC and PKCS7
加密。
我试图使用以下代码来做到这一点。 任何人都可以帮助我吗?
File file = new File("myFile.txt");
String key = readFile(new File("AESKey.bin"));
String iv = readFile(new File("AESIV.bin"));
final byte[] secretKey = key.getBytes();
final byte[] initVector = iv.getBytes();
InputStream cipherInputStream = null;
final StringBuilder output = new StringBuilder();
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(secretKey, "AES"), new
IvParameterSpec(initVector, 0, cipher.getBlockSize()));
cipherInputStream = new CipherInputStream(new FileInputStream(file), cipher);
final byte[] buffer = new byte[8192];
int read = cipherInputStream.read(buffer);
final String charsetName = "UTF-8";
while (read > -1) {
output.append(new String(buffer, 0, read, charsetName));
read = cipherInputStream.read(buffer);
}
System.out.println(output);*
这是异常 -
Exception in thread "main" java.security.NoSuchAlgorithmException: Cannot find any provider
支持AES / CBC / PKCS7Padding。
任何人都可以帮助我吗?
答案 0 :(得分:2)