gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:25:54 28 4
gpt4 key购买 nike

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

Exception in thread "main" java.security.NoSuchAlgorithmException: Cannot find any provider

支持 AES/CBC/PKCS7Padding。

有人能帮帮我吗?

最佳答案

我建议你尝试实例化密码

AES/CBC/PKCS5Padding

这是

a) JDK 支持;

b) identical in effect to PKSCS7 padding .

关于java - 如何解密在.net中加密的java文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21465637/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com