-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAESFileDecryption.java
52 lines (33 loc) · 1.52 KB
/
AESFileDecryption.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package MAIN;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JOptionPane;
public class AESFileDecryption {
public void decrypt(int key,String path)throws FileNotFoundException, IOException {
// Selecting a Image for operation
FileInputStream fis = new FileInputStream(path);
// Converting Image into byte array, create a
// array of same size as Image size
byte data[] = new byte[fis.available()];
// Read the array
fis.read(data);
int i = 0;
// Performing an XOR operation on each value of
// byte array due to which every value of Image
// will change.
for (byte b : data) {
data[i] = (byte)(b ^ key);
i++;
}
// Opening a file for writing purpose
FileOutputStream fos = new FileOutputStream(path);
// Writing new byte array value to image which
// will Encrypt it.
fos.write(data);
fos.close();
fis.close();
JOptionPane.showMessageDialog(null, "Done");
}
}