繁体   English   中英

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

[英]How to decrypt file in java which is encrypted in .net

我有一个在.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。

有人能帮帮我吗?

我建议你尝试实例化密码

AES/CBC/PKCS5Padding

是的

a)支持JDK;

b) 与PKSCS7填充相同的效果

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM