-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileDecryptor.java
More file actions
23 lines (20 loc) · 890 Bytes
/
FileDecryptor.java
File metadata and controls
23 lines (20 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.SecretKey;
import java.io.*;
public class FileDecryptor {
public static void decryptFile(String inputFile, String outputFile, SecretKey key) throws Exception {
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, key);
try (FileInputStream fis = new FileInputStream(inputFile);
CipherInputStream cis = new CipherInputStream(fis, cipher);
FileOutputStream fos = new FileOutputStream(outputFile)) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = cis.read(buffer)) != -1) {
fos.write(buffer, 0, bytesRead);
}
}
System.out.println("Decryption successful! Decrypted file saved as " + outputFile);
}
}