This project demonstrates working with cryptography (the DES encryption algorithm) in a Java program.
The Java program demonstrates the process of encrypting and decrypting text in files using the Triple DES (DESede) algorithm.
- Reads text from
inText.txt - Encrypts content with
DESedealgorithm - Decrypts the encrypted text
- Prints the original, encrypted, and decrypted text to the console
- Writes the result to the
outFile
- The
DESede(Triple DES) algorithm is considered outdated for real-world applications, but it work well for demonstrating encryption principles. - For production use more modern algorithms such as AES or RSA are recommended.
- Java SE (version 17)
- javax.crypto (
Cipher,KeyGeneration,SecretKey)
- Clone the repository:
git clone https://github.com/YuliyaZimenina/FileEncryptionAndDecription.git
cd FileEncryptionAndDecription
- Open the project in your favorite IDE (IntelliJ IDEA, Eclipse, etc.).
- Make sure Java 17 is set as the project SDK.
- Create an input file:
src/inText.txt
Put any text inside to be encrypted
- Run the
Main.javafile
public class Main {
public static void main(String[] args) throws Exception {
File inFile = new File("src\\inText.txt");
File outFile = new File("src\\outFile");
byte[] sourceText = new byte[(int) inFile.length()];
// Convert file to bytes
FileInputStream fileInputStream = new FileInputStream(inFile);
fileInputStream.read(sourceText);
for (int i = 0; i < sourceText.length; i++) {
System.out.print((char) sourceText[i]);
}
...- The result of the program:
- Source text for encryption:

