如何解密在.net中加密的java文件

时间:2014-01-30 19:23:08

标签: java .net encryption

我有一个在.Net加密的文件。我必须在java中解密该文件。 我在文本文件中有keyIV。此文件使用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。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:2)

我建议你尝试实例化密码

AES/CBC/PKCS5Padding

a)支持JDK;

b)identical in effect to PKSCS7 padding