📄 aesdecryption.java
字号:
package src;
import java.io.*;
import javax.crypto.spec.*;
import javax.crypto.*;
public class AESDecryption {
public static void main(String[] args) {
try {
String afterEncrypt = "cipher.txt";
String afterDecrypt = "final.txt";
byte[] cipherkey = KeyCipher.loadKey(afterEncrypt);
byte[] b = new byte[64];
System.arraycopy(cipherkey, 0, b, 0, 64);
byte[] aesKey = RSADecryption.decrypt(GetRSAKey.GetPrivateKey(), b);
SecretKey aks = new SecretKeySpec(aesKey, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, aks);
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(afterDecrypt));
CipherInputStream in = new CipherInputStream(
new BufferedInputStream(new FileInputStream(afterEncrypt)),
cipher);
int i;
do {
i = in.read();
if (i != -1)
out.write(i);
} while (i != -1);
in.close();
out.close();
byte[] fss = KeyCipher.readFile(afterDecrypt);
int length = fss.length;
byte[] cut = new byte[length-64];
System.arraycopy(fss, 64, cut, 0, length-64);
String s = new String(cut);
FileWriter fw = null;
fw = new FileWriter(afterDecrypt);
fw.write(s);
fw.close();
System.out.println("Decryption is successful!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -