Skip to content

Commit 456daf9

Browse files
authored
Create README.md
First version of README
1 parent 65ec513 commit 456daf9

1 file changed

Lines changed: 136 additions & 0 deletions

File tree

README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# JavaEncryptionUtility
2+
A handy utility to quickly encrypt/decrypt strings from terminal and files using AES/RSA and avoiding the use of OpenSSL binaries.
3+
4+
### Summary
5+
6+
* [Arguments List](#Arguments%20List) <br>
7+
* [Quick use](#Quick%20Use) <br>
8+
* [API](#Use%20in%20your%20projects)
9+
10+
## Arguments List
11+
12+
```
13+
----------------------------------REQUIRED ARGUMENTS--------------------------
14+
<encrypt/decrypt | encryptFile/decryptFile> Choose if you want to encrypt or decrypt data
15+
-b<AES | RSA> Choose between RSA and AES encryption
16+
\"content to encrypt goes here\"
17+
--------------------------OPTIONAL ARGUMENTS FOR AES--------------------------
18+
-s <128 | 192 | 256> specify the size of the key with one of the shown value.
19+
Default is 128.
20+
-fiv <FILELOCATION> specify the hexadecimal file where specified VI islocated
21+
-p <PASS:SALT> specify a password for encryption/decryption with the specified PASS and SALT
22+
-k <KEYFILELOCATION> specify location for setting a specific Base64 encoded key
23+
-a <CBS|CFB|OFB|CTR|GCM> choose alghorithm type
24+
Default is CBS
25+
-wiv <FILENAME> Creates a file with the latest VI used or the specified one if there is.
26+
-wk <FILENAME> Creates a file with the latest Key Encoded value used or the specified one if there is.
27+
-i <FILENAME> Input file encrypted/decrypted or physical file to encrypt/decrypt.
28+
-o <FILENAME> Output file to specify if you want to encrypt/decrypt an entire physical file or
29+
where you want to save encrypted/decrypted content.
30+
-v Set verbose to true (Use it only for encryptFile/decryptFile when files are big)
31+
Default is set to false
32+
---------------------------------OPTIONAL ARGUMENTS FOR RSA--------------------------
33+
-s <512|1024|2048|4096....|inf> Specify the key size, multiples of 2!!
34+
Default is set to 512
35+
You may need to specify -s option when encrypting/decrypting physical files
36+
-fkpr <FILENAME> Specify format private key with a PEM format from a file
37+
-fkpu <FILENAME> Specify format public key with a PEM format from a file
38+
-wkpr <FILENAME> Creates a file with the latest private key used in PEM format
39+
-wkpu <FILENAME> Creates a file with the latest public key used in PEM format
40+
-i <FILENAME> Input file encrypted/decrypted
41+
-o <FILENAME> Output file to specify if you want to encrypt/decrypt an entire file.
42+
-v Set verbose to true (Use it only for encryptFile/decryptFile when files are big)
43+
Default is set to false
44+
```
45+
## Quick Use
46+
47+
#### Examples
48+
49+
```
50+
1)Encrypt a string from terminal with AES. It will create files with iv and key respectively with names: iv.txt and key.txt
51+
java -jar JavaEncrytionUtility.jar encrypt -bAES -wiv iv.txt -wk key.txt -s 256 -a CBS "ThisContentWillBeEncrypted"
52+
53+
2)Encrypt a string from terminal with RSA writing the generated key pair in private.txt and public.txt files.
54+
java -jar JavaEncrytionUtility.jar decrypt -bRSA -s 4096 -wkpr private.txt -wkpu public.txt "ThisContentWillBeEncrypted"
55+
56+
3)Decrypt a string from terminal with AES using iv and key generated in the (1) step.
57+
java -jar JavaEncrytionUtility.jar decrypt -bAES -s 256 -a CBS -fiv iv.txt -k key.txt "EncryptedStringFromStep1"
58+
59+
4)Decrypt a string from terminal with RSA reading the generated key pair from files generated from step (2). Supported format for private and public key is PEM, use your own if you have.
60+
java -jar JavaEncrytionUtility.jar decrypt -bRSA -s 4096 -fkpr private.txt -fkpu public.txt "EncryptedContentFromTheStep2"
61+
62+
5)Encrypt the content of a file and saving it into an output file with AES.
63+
java -jar JavaEncrytionUtility.jar encrypt -bAES -wiv iv.txt -wk key.txt -s 256 -a CBS -i inputToEncrypt.txt -o outputEncrypted.txt
64+
65+
6)Encrypt the content of a file and saving it into an output file with RSA.
66+
java -jar JavaEncrytionUtility.jar encrypt -bRSA -s 4096 -wkpr private.txt -wkpu public.txt -i inputToEncrypt.txt -o outputEncrypted.txt
67+
68+
7)Decrypt the content of a file from terminal with AES using encrypted output file from the step (5)
69+
java -jar JavaEncrytionUtility.jar decrypt -bAES -fiv iv.txt -k key.txt -s 256 -a CBS -i outputEncrypted.txt -o decrypted.txt
70+
71+
8)Decrypt the content of a file from terminal with RSA using encrypted output file from the step (6)
72+
java -jar JavaEncrytionUtility.jar decrypt -bRSA -s 4096 -fkpr private.txt -fkpu public.txt -i outputEncrypted.txt -o decrypted.txt
73+
74+
9)Encrypt a file with AES (The difference with the example 5 is that this method is specifically coded also for huge files)
75+
java -jar JavaEncrytionUtility.jar encryptFile -bAES -wiv iv.txt -wk key.txt -s 256 -a CBS -i fileToEncrypt.txt -o saveEncrypted.txt
76+
77+
10)Encrypt a file with RSA (The difference with the example 6 is that this method is specifically coded also for huge files)
78+
WARNING: RSA is not made for encrypt/decrypt huge files. It is extremely slow. Use it only for educational purpose or with files which their size is few kbs.
79+
java -jar JavaEncrytionUtility.jar encryptFile -bRSA -s 4096 -wkpr private.txt -wkpu public.txt -i inputToEncrypt.txt -o outputEncrypted.txt
80+
81+
11)Decrypt a file with AES
82+
java -jar JavaEncrytionUtility.jar decryptFile -bAES -fiv iv.txt -k key.txt -s 256 -a CBS -i saveEncrypted.txt -o decrypted.txt
83+
84+
10)Decrypt a file with RSA
85+
WARNING: RSA is not made for encrypt/decrypt huge files. It is extremely slow. Use it only for educational purpose or with files which their size is few kbs.
86+
java -jar JavaEncrytionUtility.jar decryptFile -bRSA -s 4096 -fkpr private.txt -fkpu public.txt -i outputEncrypted.txt -o decrypted.txt
87+
88+
```
89+
90+
You can also consider to use binaries frovided for each operating system instead of the Jar file.
91+
92+
## Use in your projects
93+
94+
### Import
95+
Import the jar in your project. How to do it depends on what IDE you're using.
96+
97+
### AES
98+
99+
```java
100+
OperatingSystemAbstract o = new Windows(new Linux(new MacOSX(null))); //Detect Operating System
101+
OperatingSystemAbstract op = o.matches(null);
102+
103+
List<Logger> loggers = new ArrayList<>();
104+
loggers.add(new ConsoleLogger(op));
105+
SimmetricEncryption enc = new AESEncryption(loggers);
106+
enc.generateKey(256);
107+
enc.writeIv(new File("iv.txt"));
108+
enc.wrtieKey(new File("key.txt"));
109+
110+
String encrypted = enc.encryptMessage("encrypt Me");
111+
System.out.println("Encrypted: "+encrypted + "\nDecrypted: " + enc.decryptMessage(encrypted));
112+
loggers.forEach(x -> System.out.print(x.getLogs())); //Print logs infos
113+
```
114+
115+
### RSA
116+
117+
```java
118+
OperatingSystemAbstract o = new Windows(new Linux(new MacOSX(null))); //Detect Operating System
119+
OperatingSystemAbstract op = o.matches(null);
120+
121+
List<Logger> loggers = new ArrayList<>();
122+
loggers.add(new ConsoleLogger(op));
123+
AsyncEncryption enc = new RSAEncryption(loggers);
124+
enc.setKeySize(4096);
125+
enc.writePublicKeyToFile(new File("public.txt"));
126+
enc.writePrivateKeyToFile(new File("private.txt"));
127+
128+
String encrypted = enc.encryptMessage("encrypt Me");
129+
System.out.println("Encrypted: "+encrypted + "\nDecrypted: " + enc.decryptMessage(encrypted));
130+
loggers.forEach(x -> System.out.print(x.getLogs())); //Print logs infos
131+
132+
```
133+
134+
For the remaining methods and infos check generated JavaDoc.
135+
136+

0 commit comments

Comments
 (0)