Skip to content

Commit feb09b9

Browse files
committed
Update Number 1
1 parent 65ec513 commit feb09b9

6 files changed

Lines changed: 117 additions & 32 deletions

File tree

src/main/java/Arguments/DetectArgumentsFacade.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919
import java.security.InvalidKeyException;
2020
import java.security.NoSuchAlgorithmException;
2121
import java.security.spec.InvalidKeySpecException;
22-
import java.util.Arrays;
2322
import java.util.List;
2423

2524
public class DetectArgumentsFacade implements Runnable {
2625

27-
private final String[] args;
26+
private final List<String> args;
2827
private final List<Logger> logger;
2928

30-
public DetectArgumentsFacade(String[] arguments, List<Logger> log) {
29+
public DetectArgumentsFacade(List<String> arguments, List<Logger> log) {
3130
this.args = arguments;
3231
this.logger = log;
3332
}
@@ -48,7 +47,7 @@ public void detectArguments() throws InterruptedException, NoSuchAlgorithmExcept
4847
OperatingSystemAbstract finalOP = op.matches(null);
4948
this.logger.add(FactoryClassUtility.getShellLogger(finalOP));
5049
encryptionsAvailable.setLoggers(logger);
51-
Encryption enc = encryptionsAvailable.matches(Arrays.asList(args), this.logger);
50+
Encryption enc = encryptionsAvailable.matches(args, this.logger);
5251
if (enc == null) {
5352
main.usage();
5453
throw new ArgumentsNotValidException("You must choose to use RSA or AES with -b option");

src/main/java/Encryption/AESEncryption.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public void writeIv(File file) throws IOException {
115115
loggers.forEach(x -> x.log("IV wrote into: " + file.toPath()));
116116
}
117117

118+
118119
private IvParameterSpec generateIv() {
119120
byte[] iv = new byte[16];
120121
new SecureRandom().nextBytes(iv);

src/main/java/Encryption/AsyncEncryption.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,66 @@
1919
* Default is set to false
2020
**/
2121
public interface AsyncEncryption extends Encryption {
22+
/**
23+
* Get Public Key in PEM Format
24+
*
25+
* @return PEM public key as a string
26+
*/
2227
String getPEMPublicKey();
2328

29+
/**
30+
* Get Private Key in PEM Format
31+
*
32+
* @return PEM private key as a string
33+
*/
2434
String getPEMPrivateKey();
2535

36+
/**
37+
* Set the size key. Should be a power of 2. 2^10=1024 for example.
38+
*
39+
* @return void
40+
*/
2641
void setKeySize(int size) throws NoSuchAlgorithmException;
2742

43+
/**
44+
* Set the public key. You should provide a public key with the following format:
45+
* <p>
46+
* -----BEGIN PUBLIC KEY-----
47+
* XXXXXXXXXXXXXXXXXXXXXXXXXX
48+
* -----END PUBLIC KEY-----
49+
*
50+
* @param publicKey
51+
* @throws InvalidKeySpecException The Specified key is not in the correct format.
52+
* @throws NoSuchAlgorithmException Algorithm not found.
53+
*/
2854
void setPublicKey(String publicKey) throws InvalidKeySpecException, NoSuchAlgorithmException;
2955

56+
/**
57+
* Set the private key. You should provide a private key with the following format:
58+
* <p>
59+
* -----BEGIN RSA PRIVATE KEY-----
60+
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
61+
* -----END RSA PRIVATE KEY-----
62+
*
63+
* @param privateKey
64+
* @throws InvalidKeySpecException The Specified key is not in the correct format.
65+
* @throws NoSuchAlgorithmException Algorithm not found.
66+
*/
3067
void setPrivateKey(String privateKey) throws InvalidKeySpecException, NoSuchAlgorithmException;
3168

69+
/**
70+
* Write the generated or set public key into a file with a PEM format.
71+
*
72+
* @param file
73+
* @throws IOException
74+
*/
3275
void writePublicKeyToFile(File file) throws IOException;
3376

77+
/**
78+
* Write the generated or set private key into a file with a PEM format.
79+
*
80+
* @param file
81+
* @throws IOException
82+
*/
3483
void writePrivateKeyToFile(File file) throws IOException;
3584
}

src/main/java/Encryption/SimmetricEncryption.java

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
import java.security.spec.InvalidKeySpecException;
99

1010
/**
11-
* -s <128 | 192 | 256> specify the size of the key with one of the shown value. \n" +
12-
* Default is 128. \n" +
13-
* -fiv <FILELOCATION> specify the hexadecimal file where specified VI islocated \n" +
14-
* -p <PASS:SALT> specify a password for encryption/decryption with the specified PASS and SALT \n" +
15-
* -k <KEYFILELOCATION> specify location for setting a specific Base64 encoded key \n" +
16-
* -a <CBS|CFB|OFB|CTR|GCM> choose alghorithm type \n" +
17-
* Default is CBS \n" +
18-
* -wiv <FILENAME> Creates a file with the latest VI used or the specified one if there is. \n" +
19-
* -wk <FILENAME> Creates a file with the latest Key Encoded value used or the specified one if there is. \n" +
20-
* -i <FILENAME> Input file encrypted/decrypted or physical file to encrypt/decrypt. \n" +
21-
* -o <FILENAME> Output file to specify if you want to encrypt/decrypt an entire physical file or \n" +
22-
* where you want to save encrypted/decrypted content. \n" +
23-
* -v Set verbose to true \n" +
11+
* -s <128 | 192 | 256> specify the size of the key with one of the shown value.
12+
* Default is 128.
13+
* -fiv <FILELOCATION> specify the hexadecimal file where specified VI islocated
14+
* -p <PASS:SALT> specify a password for encryption/decryption with the specified PASS and SALT
15+
* -k <KEYFILELOCATION> specify location for setting a specific Base64 encoded key
16+
* -a <CBS|CFB|OFB|CTR|GCM> choose alghorithm type
17+
* Default is CBS
18+
* -wiv <FILENAME> Creates a file with the latest VI used or the specified one if there is.
19+
* -wk <FILENAME> Creates a file with the latest Key Encoded value used or the specified one if there is.
20+
* -i <FILENAME> Input file encrypted/decrypted or physical file to encrypt/decrypt.
21+
* -o <FILENAME> Output file to specify if you want to encrypt/decrypt an entire physical file or
22+
* where you want to save encrypted/decrypted content.
23+
* -v Set verbose to true
2424
* Default is set to false
25-
*/
25+
**/
2626
public interface SimmetricEncryption extends Encryption {
2727
/**
2828
* The method can be used to set a password to encrypt data
@@ -43,16 +43,49 @@ public interface SimmetricEncryption extends Encryption {
4343
*/
4444
void setIv(String iv);
4545

46+
/**
47+
* Write Iv Generated (Or set with setIv method) in a file.
48+
*
49+
* @param file
50+
* @throws IOException
51+
*/
4652
void writeIv(File file) throws IOException;
4753

54+
/**
55+
* Write Key Generated (Or set with setKey method) in a file.
56+
*
57+
* @param file
58+
* @throws IOException
59+
*/
4860
void writeKey(File file) throws IOException;
4961

62+
/**
63+
* Set size with the generated key which will be used when encrypting/decrypting.
64+
*
65+
* @param size
66+
*/
5067
void setSize(int size);
5168

69+
/**
70+
* Set algorithm default: AES/CBC/PKCS5Padding
71+
* Replace CBS with CFB OR OFB OR CTR OR GCM.
72+
*
73+
* @param algo
74+
*/
5275
void setAlgo(String algo);
5376

77+
/**
78+
* Get the generated IV or setted IV as a string of bytes
79+
*
80+
* @return
81+
*/
5482
String getIV();
5583

84+
/**
85+
* Get the generated key as Base64 encoded String value.
86+
*
87+
* @return
88+
*/
5689
String getKey();
5790

5891
/**
@@ -61,4 +94,5 @@ public interface SimmetricEncryption extends Encryption {
6194
* @param password set the encoded password for the AES cipher
6295
*/
6396
void setKey(String password);
97+
6498
}

src/main/java/Loggers/ConsoleLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public void changeableLogger(String str) {
5454
}
5555

5656
@Override
57-
public String getHasChangedLog() throws IOException {
57+
public String getHasChangedLog() throws IOException, InterruptedException {
5858
boolean cng = this.changed;
5959
if (cng) {
6060
this.changed = false;
61-
new ProcessBuilder(this.op.clearTerminalCommand()).inheritIO().start();
61+
new ProcessBuilder(this.op.clearTerminalCommand()).inheritIO().start().waitFor();//waitFor(100,TimeUnit.MILLISECONDS);
6262
return changeableBuilder.toString();
6363
}
6464
return null;

src/main/java/main/main.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.io.IOException;
88
import java.util.ArrayList;
9+
import java.util.Arrays;
910
import java.util.List;
1011

1112
public class main {
@@ -22,7 +23,7 @@ public static void usage() {
2223
" -fiv <FILELOCATION> specify the hexadecimal file where specified VI islocated \n" +
2324
" -p <PASS:SALT> specify a password for encryption/decryption with the specified PASS and SALT \n" +
2425
" -k <KEYFILELOCATION> specify location for setting a specific Base64 encoded key \n" +
25-
" -a <CBS|CFB|OFB|CTR|GCM> choose alghorithm type \n" +
26+
" -a <CBC|CFB|OFB|CTR> choose alghorithm type \n" +
2627
" Default is CBS \n" +
2728
" -wiv <FILENAME> Creates a file with the latest VI used or the specified one if there is. \n" +
2829
" -wk <FILENAME> Creates a file with the latest Key Encoded value used or the specified one if there is. \n" +
@@ -59,28 +60,29 @@ public static void main(String... args) throws InterruptedException, IOException
5960
System.exit(0);
6061
}
6162

62-
DetectArgumentsFacade instance = new DetectArgumentsFacade(args, new ArrayList<>());
63+
List<String> arguments = Arrays.asList(args);
64+
65+
DetectArgumentsFacade instance = new DetectArgumentsFacade(arguments, new ArrayList<>());
6366
Thread a = new Thread(instance);
6467
a.start();
6568

6669
List<Logger> loggers = instance.getLoggers();
70+
boolean bool = false;
6771

68-
while (true) {
69-
/*
70-
loggers.forEach(x -> {
71-
String s = x.getLogs();
72-
if (!s.isEmpty())
73-
System.out.print(s);
74-
});
72+
if (arguments.contains("-v"))
73+
bool = true;
7574

76-
*/
75+
while (true) {
7776
for (Logger x : loggers) {
7877
String s = x.getHasChangedLog();
7978
String z = x.getLogs();
80-
if (!z.isEmpty())
79+
if (z != null && !z.isEmpty())
8180
System.out.print(z);
82-
if (s != null)
81+
if (s != null) {
8382
System.out.print(s);
83+
if (bool)
84+
Thread.sleep(250);
85+
}
8486
}
8587
}
8688
}

0 commit comments

Comments
 (0)