簡體   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