Skip to content

Commit f3218f9

Browse files
committed
Initial Commit
0 parents  commit f3218f9

57 files changed

Lines changed: 2554 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
*.txt
7+
8+
# BlueJ files
9+
*.ctxt
10+
11+
# Mobile Tools for Java (J2ME)
12+
.mtj.tmp/
13+
14+
# Package Files #
15+
*.jar
16+
*.war
17+
*.nar
18+
*.ear
19+
*.zip
20+
*.tar.gz
21+
*.rar
22+
23+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24+
hs_err_pid*

JavaEncryptionUtility.iml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10+
<excludeFolder url="file://$MODULE_DIR$/target" />
11+
</content>
12+
<orderEntry type="inheritedJdk" />
13+
<orderEntry type="sourceFolder" forTests="false" />
14+
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.15" level="project" />
15+
</component>
16+
</module>

src/javarunargs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
java -classpath "C:\Users\Anon3r\IdeaProjects\JavaEncryptionUtility\target\classes;C:\Users\Anon3r\.m2\repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar" main.main
2+
3+
java -classpath "C:\Users\Anon3r\.m2\repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar" main.main
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package Arguments;
2+
3+
import Encryption.Encryption;
4+
import Exceptions.AESSpecifyPassword;
5+
import Exceptions.ArgumentsNotValidException;
6+
import Exceptions.Base64NotValid;
7+
import Loggers.Logger;
8+
9+
import javax.crypto.BadPaddingException;
10+
import javax.crypto.IllegalBlockSizeException;
11+
import javax.crypto.NoSuchPaddingException;
12+
import java.io.IOException;
13+
import java.security.InvalidAlgorithmParameterException;
14+
import java.security.InvalidKeyException;
15+
import java.security.NoSuchAlgorithmException;
16+
import java.security.spec.InvalidKeySpecException;
17+
import java.util.List;
18+
19+
public interface Arguments {
20+
Encryption matches(List<String> args, List<Logger> loggers) throws InterruptedException, NoSuchAlgorithmException, InvalidKeySpecException, IOException, AESSpecifyPassword, ArgumentsNotValidException, InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, NoSuchPaddingException, Base64NotValid;
21+
22+
List<Logger> getLoggers();
23+
24+
void setLoggers(List<Logger> loggers);
25+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package Arguments;
2+
3+
import Arguments.ObjectBuilderAES.*;
4+
import Encryption.Encryption;
5+
import Encryption.SimmetricEncryption;
6+
import Exceptions.AESSpecifyPassword;
7+
import Exceptions.ArgumentsNotValidException;
8+
import Exceptions.Base64NotValid;
9+
import Loggers.Logger;
10+
import Utilites.FactoryClassUtility;
11+
12+
import javax.crypto.BadPaddingException;
13+
import javax.crypto.IllegalBlockSizeException;
14+
import javax.crypto.NoSuchPaddingException;
15+
import java.io.IOException;
16+
import java.security.InvalidAlgorithmParameterException;
17+
import java.security.InvalidKeyException;
18+
import java.security.NoSuchAlgorithmException;
19+
import java.security.spec.InvalidKeySpecException;
20+
import java.util.List;
21+
22+
public class DetectAESEncryption extends DetectArguments {
23+
public DetectAESEncryption(Arguments obj) {
24+
super(obj);
25+
}
26+
27+
@Override
28+
public Encryption matches(List<String> args, List<Logger> loggers) throws InterruptedException, NoSuchAlgorithmException, InvalidKeySpecException, IOException, AESSpecifyPassword, ArgumentsNotValidException, InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, NoSuchPaddingException, Base64NotValid {
29+
if (args.contains("-bAES")) {
30+
// initialize constructors with factory class utility
31+
ObjBuilderAES objectBuilder =
32+
new VerbosityMatching(
33+
new KeyAESMatching(
34+
new IVAESMatching(
35+
new SizeKeyAESMatching(
36+
new AlgorithmAESMatching(
37+
new PasswordAESMatching(
38+
new OutputFileAESMatching(
39+
new InputFileAESMatching(
40+
new WriteKEYAESMatching(
41+
new WriteIVAESMatching(
42+
new FinalEncryptionFromTerminal(
43+
new FinalDecryptionFromTerminal(
44+
new FinalEncryptionFile(
45+
new FinalDecryptionFile(
46+
null
47+
)
48+
)
49+
)
50+
)
51+
)
52+
)
53+
)
54+
)
55+
)
56+
)
57+
)
58+
)));
59+
SimmetricEncryption instance = FactoryClassUtility.AESInstance(loggers);
60+
ObjBuilderAES t = objectBuilder.matchBuilder(instance, args, loggers);
61+
return instance;
62+
}
63+
return super.matches(args, loggers);
64+
}
65+
66+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package Arguments;
2+
3+
import Encryption.Encryption;
4+
import Exceptions.AESSpecifyPassword;
5+
import Exceptions.ArgumentsNotValidException;
6+
import Exceptions.Base64NotValid;
7+
import Loggers.Logger;
8+
9+
import javax.crypto.BadPaddingException;
10+
import javax.crypto.IllegalBlockSizeException;
11+
import javax.crypto.NoSuchPaddingException;
12+
import java.io.IOException;
13+
import java.security.InvalidAlgorithmParameterException;
14+
import java.security.InvalidKeyException;
15+
import java.security.NoSuchAlgorithmException;
16+
import java.security.spec.InvalidKeySpecException;
17+
import java.util.List;
18+
19+
public abstract class DetectArguments implements Arguments {
20+
private final Arguments obj;
21+
private List<Logger> loggers;
22+
23+
public DetectArguments(Arguments obj) {
24+
this.obj = obj;
25+
}
26+
27+
28+
@Override
29+
public Encryption matches(List<String> args, List<Logger> loggers) throws InterruptedException, NoSuchAlgorithmException, InvalidKeySpecException, IOException, AESSpecifyPassword, ArgumentsNotValidException, InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, NoSuchPaddingException, Base64NotValid {
30+
if (this.obj != null) {
31+
return this.obj.matches(args, loggers);
32+
}
33+
return null;
34+
}
35+
36+
@Override
37+
public List<Logger> getLoggers() {
38+
return this.loggers;
39+
}
40+
41+
@Override
42+
public void setLoggers(List<Logger> loggers) {
43+
this.loggers = loggers;
44+
}
45+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package Arguments;
2+
3+
import Encryption.Encryption;
4+
import Exceptions.AESSpecifyPassword;
5+
import Exceptions.ArgumentsNotValidException;
6+
import Exceptions.Base64NotValid;
7+
import Loggers.Logger;
8+
import OperatingSystem.Linux;
9+
import OperatingSystem.OperatingSystemAbstract;
10+
import OperatingSystem.Windows;
11+
import Utilites.FactoryClassUtility;
12+
import main.main;
13+
14+
import javax.crypto.BadPaddingException;
15+
import javax.crypto.IllegalBlockSizeException;
16+
import javax.crypto.NoSuchPaddingException;
17+
import java.io.IOException;
18+
import java.security.InvalidAlgorithmParameterException;
19+
import java.security.InvalidKeyException;
20+
import java.security.NoSuchAlgorithmException;
21+
import java.security.spec.InvalidKeySpecException;
22+
import java.util.Arrays;
23+
import java.util.List;
24+
25+
public class DetectArgumentsFacade implements Runnable {
26+
27+
private final String[] args;
28+
private final List<Logger> logger;
29+
30+
public DetectArgumentsFacade(String[] arguments, List<Logger> log) {
31+
this.args = arguments;
32+
this.logger = log;
33+
}
34+
35+
public List<Logger> getLoggers() {
36+
return this.logger;
37+
}
38+
39+
public void detectArguments() throws InterruptedException, NoSuchAlgorithmException, InvalidKeySpecException, IOException, AESSpecifyPassword, ArgumentsNotValidException, IllegalBlockSizeException, NoSuchPaddingException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, Base64NotValid {
40+
Arguments encryptionsAvailable = new DetectAESEncryption(
41+
new DetectRSAEncryption(null));
42+
43+
OperatingSystemAbstract op = new Linux(
44+
new Linux(
45+
new Windows(null)
46+
)
47+
);
48+
OperatingSystemAbstract finalOP = op.matches(null);
49+
this.logger.add(FactoryClassUtility.getShellLogger(finalOP));
50+
encryptionsAvailable.setLoggers(logger);
51+
Encryption enc = encryptionsAvailable.matches(Arrays.asList(args), this.logger);
52+
if (enc == null) {
53+
main.usage();
54+
throw new ArgumentsNotValidException("You must choose to use RSA or AES with -b option");
55+
}
56+
}
57+
58+
@Override
59+
public void run() {
60+
try {
61+
this.detectArguments();
62+
System.exit(0);
63+
} catch (Exception ex) {
64+
System.out.println("Exception raised while processing: " + ex);
65+
System.exit(-1);
66+
}
67+
}
68+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package Arguments;
2+
3+
import Arguments.ObjectBuilderRSA.*;
4+
import Encryption.AsyncEncryption;
5+
import Encryption.Encryption;
6+
import Exceptions.AESSpecifyPassword;
7+
import Exceptions.ArgumentsNotValidException;
8+
import Exceptions.Base64NotValid;
9+
import Loggers.Logger;
10+
import Utilites.FactoryClassUtility;
11+
12+
import javax.crypto.BadPaddingException;
13+
import javax.crypto.IllegalBlockSizeException;
14+
import javax.crypto.NoSuchPaddingException;
15+
import java.io.IOException;
16+
import java.security.InvalidAlgorithmParameterException;
17+
import java.security.InvalidKeyException;
18+
import java.security.NoSuchAlgorithmException;
19+
import java.security.spec.InvalidKeySpecException;
20+
import java.util.List;
21+
22+
public class DetectRSAEncryption extends DetectArguments {
23+
public DetectRSAEncryption(Arguments obj) {
24+
super(obj);
25+
}
26+
27+
@Override
28+
public Encryption matches(List<String> args, List<Logger> loggers) throws InterruptedException, NoSuchAlgorithmException, InvalidKeySpecException, IOException, AESSpecifyPassword, ArgumentsNotValidException, IllegalBlockSizeException, NoSuchPaddingException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, Base64NotValid {
29+
if (args.contains("-bRSA")) {
30+
// initialize constructors with factory class utility
31+
ObjectBuilderRSA builderRSA =
32+
new SizeKeyRSAMatching(
33+
new VerbosityMatchingRSA(
34+
new InputPublicKeyRSAMatching(
35+
new InputPrivateKeyRSAMatching(
36+
new InputFileRSAMatching(
37+
new OutputFileRSAMatching(
38+
new WritePrivateKeyRSAMatching(
39+
new WritePublicKeyRSAMatching(
40+
new FinalEncryptionFromTerminal(
41+
new FinalDecryptionFromTerminal(
42+
new FinalEncryptionFile(
43+
new FinalDecryptionFile(
44+
null
45+
)
46+
)
47+
)
48+
)
49+
)
50+
)
51+
)
52+
)
53+
)
54+
)
55+
)
56+
);
57+
AsyncEncryption instance = FactoryClassUtility.RSAInstance(loggers);
58+
ObjectBuilderRSA t = builderRSA.matchBuilder(instance, args, loggers);
59+
return instance;
60+
}
61+
return super.matches(args, loggers);
62+
}
63+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package Arguments.ObjectBuilderAES;
2+
3+
import Encryption.SimmetricEncryption;
4+
import Exceptions.AESSpecifyPassword;
5+
import Exceptions.ArgumentsNotValidException;
6+
import Exceptions.Base64NotValid;
7+
import Loggers.Logger;
8+
9+
import javax.crypto.BadPaddingException;
10+
import javax.crypto.IllegalBlockSizeException;
11+
import javax.crypto.NoSuchPaddingException;
12+
import java.io.IOException;
13+
import java.security.InvalidAlgorithmParameterException;
14+
import java.security.InvalidKeyException;
15+
import java.security.NoSuchAlgorithmException;
16+
import java.security.spec.InvalidKeySpecException;
17+
import java.util.List;
18+
19+
public class AlgorithmAESMatching extends ObjBuilderAESAbstract {
20+
21+
public AlgorithmAESMatching(ObjBuilderAES aes) {
22+
super(aes);
23+
}
24+
25+
26+
@Override
27+
public ObjBuilderAES matchBuilder(SimmetricEncryption encryptionInstance, List<String> args, List<Logger> loggers) throws ArgumentsNotValidException, IOException, NoSuchAlgorithmException, AESSpecifyPassword, InvalidKeySpecException, BadPaddingException, InterruptedException, InvalidKeyException, IllegalBlockSizeException, Base64NotValid, NoSuchPaddingException, InvalidAlgorithmParameterException {
28+
if (args.contains("-a")) {
29+
int position = args.indexOf("-a");
30+
String value = args.get(position + 1);
31+
if (value.isEmpty())
32+
throw new ArgumentsNotValidException("-a argument value cannot be empty");
33+
loggers.forEach(x -> x.log("[Algorithm request detected => " + value + "]"));
34+
encryptionInstance.setAlgo("AES/" + value.toUpperCase() + "/PKCS5Padding");
35+
}
36+
return super.matchBuilder(encryptionInstance, args, loggers);
37+
}
38+
}

0 commit comments

Comments
 (0)