The first thing to do is to install java. This works differently with each operating system.
sudo apt update && sudo apt upgrade -y
sudo apt install -y coreutils default-jre default-jdk dos2unix
The commands for Java are platform independent. Therefore, it doesn't matter if you run it on Linux or Windows.
- If you have installed Java, you can build the project directly with
make
.
make
- Linux
dos2unix makefile.sh
chmod +x makefile.sh
sudo sh makefile.sh
- Windows
./makefile.cmd
The command javac -Xlint:unchecked ./javacrypt/*.java
compiles all the Java files in the ./javacrypt
directory with the -Xlint:unchecked
option to display warnings for unchecked operations.
javac -Xlint:unchecked ./javacrypt/*.java
The command jar cfm MyCrypt.jar ./manifest.mf javacrypt/*.class
creates a JAR (Java Archive) file named MyCrypt.jar
with the specified manifest file (manifest.mf
) and includes all the class files (*.class
) in the javacrypt
directory.
jar cfm JavaCrypt.jar manifest.mf javacrypt/*.class
java -jar JavaCrypt.jar
Before you can use the encryption, you need to generate it with keys. The keys are stored in binary form. Therefore, they cannot be opened with a normal editor. The public key is needed for encryption and the private key for decryption.
java -jar JavaCrypt.jar -genkeys <PUBLIC-KEY> <PRIVATE-KEY>
For the encryption you need three files. A public key, the file to be encrypted and the output file. With the flag "-encrypt" and the correct specification of the files the file will be encrypted.
java -jar JavaCrypt.jar -encrypt <PUBLIC-KEY> <FILE> <ENCRYPTED-FILE>
For decryption, you need three files. A private key, the file to be decrypted and the output file. By the flag "-decrypt" and the correct specification of the files the file is decrypted.
java -jar JavaCrypt.jar -decrypt <PRIVATE-KEY> <ENCRYPTED-FILE> <DECRYPT-FILE>
The copying of files is a function that has arisen more through the others. For this reason one must also specify a "dummy word". But it doesn't matter which string you enter, because it will be ignored.
java -jar JavaCrypt.jar -copy dummy text.txt text_copy.txt
➜ JavaCrypt git:(main) ✗ javac -Xlint:unchecked ./javacrypt/*.java
➜ JavaCrypt git:(main) ✗ jar cfm JavaCrypt.jar manifest.mf javacrypt/*.class
➜ JavaCrypt git:(main) ✗ java -jar JavaCrypt.jar
Program 'JavaCrypt'
Usage:
JavaCrypt -genkeys [priv_keyfile] [pub_keyfile]
JavaCrypt -encrypt [pub_keyfile] [ifile] [ofile]
JavaCrypt -decrypt [privkeyfile] [ifile] [ofile]
JavaCrypt -copy [dummyword] [ifile] [ofile]
➜ JavaCrypt git:(main) ✗ java -jar JavaCrypt.jar -genkeys priv.key pub.key
RunGenKeys
Private key file: /mnt/e/git_eskopp/JavaCrypt/priv.key
Public key file: /mnt/e/git_eskopp/JavaCrypt/pub.key
End of the program.
➜ JavaCrypt git:(main) ✗ echo "Hello World" > test.txt
➜ JavaCrypt git:(main) ✗ java -jar JavaCrypt.jar -encrypt pub.key test.txt test_encrypt.txt
RunEncrypt
Number of bytes transferred: 128
End of the program.
➜ JavaCrypt git:(main) ✗ cat test_encrypt.txt
...
➜ JavaCrypt git:(main) ✗ java -jar JavaCrypt.jar -decrypt priv.key test_encrypt.txt test_decrypt.txt
RunDecrypt
Number of bytes transferred: 128
End of the program.
➜ JavaCrypt git:(main) ✗ cat test_decrypt.txt
Hello World