List of Topics:
Location Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How to Implement TripleDES Encryption and Decryption of a Text File using Java?

Encrypt and Decrypt Text File using TripleDES in Java

Condition for Encrypt and Decrypt Text File using TripleDES in Java

  • Description:
    To enhance the security of data, TripleDES (3DES) applies the DES algorithm three times using two or three unique 56-bit keys, resulting in an effective key length of 112 or 168 bits. The encryption process involves three stages: encrypting with the first key (Key1), decrypting with the second key (Key2), and encrypting again with the third key (Key3). In Java, the Cipher class supports TripleDES using the "DESede" algorithm.
    A SecretKey object manages the keys, which are typically generated with KeyGenerator. The Cipher must be initialized in ENCRYPT_MODE or DECRYPT_MODE to perform the desired operation. To handle files securely, CipherOutputStream and CipherInputStream provide encrypted or decrypted data streams. Effective key management ensures strong security, while padding schemes like PKCS5Padding handle data alignment issues. It is crucial to manage exceptions such as InvalidKeyException and close file streams properly to ensure data integrity and prevent resource leaks.
Sample Code
  • Encryption:
    package symmetric;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.util.Base64;
    import javax.crypto.Cipher;
    import javax.crypto.SecretKey;
    import javax.crypto.spec.SecretKeySpec;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;
    public class TripleDES_Alg_Encryption extends javax.swing.JFrame {
    private int result;
    private SecretKey serverSecretKey;
    private String keyFilePath = "/home/soft20/NetBeansProjects/TripleDES/secret.key";
    public TripleDES_Alg_Encryption() {
    initComponents();
    serverSecretKey = loadSecretKey(keyFilePath);
    }
    @SuppressWarnings("unchecked")
    // //GEN-BEGIN:initComponents
    private void initComponents() {
    jLabel1 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jTextField2 = new javax.swing.JTextField();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jButton4 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jLabel1.setText("TripleDes_Alg_Encryption");
    jLabel2.setText("File Path");
    jLabel3.setText("File Path");
    jButton1.setText("Choose File");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    }
    });
    jButton2.setText("Choose File");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton2ActionPerformed(evt);
    }
    });
    jButton3.setText("ENCRYPT");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton3ActionPerformed(evt);
    }
    });
    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane1.setViewportView(jTextArea1);
    jButton4.setText("SecretKey");
    jButton4.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton4ActionPerformed(evt);
    }
    });
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
    .addGap(0, 0, Short.MAX_VALUE)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING))
    .addGap(201, 201, 201))
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(169, 169, 169)
    .addComponent(jLabel1))
    .addGroup(layout.createSequentialGroup()
    .addGap(76, 76, 76)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(jLabel2)
    .addComponent(jLabel3))
    .addGap(34, 34, 34)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(jButton3)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE))))
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 451, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addGroup(layout.createSequentialGroup()
    .addGap(199, 199, 199)
    .addComponent(jButton4)))
    .addContainerGap(62, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(32, 32, 32)
    .addComponent(jLabel1)
    .addGap(27, 27, 27)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jLabel2))
    .addGap(18, 18, 18)
    .addComponent(jButton1)
    .addGap(27, 27, 27)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jLabel3))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
    .addComponent(jButton2)
    .addGap(30, 30, 30)
    .addComponent(jButton3)
    .addGap(18, 18, 18)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(18, 18, 18)
    .addComponent(jButton4)
    .addContainerGap(25, Short.MAX_VALUE))
    );
    pack();
    }//
    //GEN-END:initComponents
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Choose a file");
    result = fileChooser.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
    File selectedFile = fileChooser.getSelectedFile();
    jTextField1.setText(selectedFile.getAbsolutePath());
    } else {
    jTextField1.setText("No File Selected ");
    }
    }//GEN-LAST:event_jButton1ActionPerformed
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Choose a file");
    result = fileChooser.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
    File selectedFile = fileChooser.getSelectedFile();
    jTextField2.setText(selectedFile.getAbsolutePath());
    } else {
    jTextField2.setText("No File Selected ");
    }
    }//GEN-LAST:event_jButton2ActionPerformed
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    display();
    }//GEN-LAST:event_jButton4ActionPerformed
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    String inputFilePath = jTextField1.getText();
    String outputFilePath = jTextField2.getText();
    try {
    encrypt(inputFilePath, outputFilePath, serverSecretKey);
    JOptionPane.showMessageDialog(this, "File encrypted successfully.");
    } catch (Exception e) {
    System.out.println(e.getMessage());
    }
    }//GEN-LAST:event_jButton3ActionPerformed
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(() -> {
    new TripleDES_Alg_Encryption().setVisible(true);
    });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
    private SecretKey loadSecretKey(String keyFilePath) {
    try (BufferedReader reader = new BufferedReader(new FileReader(keyFilePath))) {
    String base64Key = reader.readLine();
    byte[] decodedKey = Base64.getDecoder().decode(base64Key);
    return new SecretKeySpec(decodedKey, 0, decodedKey.length, "DESede");
    } catch (Exception e) {
    JOptionPane.showMessageDialog(this, "Error loading secret key: " + e.getMessage());
    return null;
    }
    }
    private void display() {
    try {
    byte[] publicKeyBytes = serverSecretKey.getEncoded();
    String res = Base64.getEncoder().encodeToString(publicKeyBytes);
    jTextArea1.setText(res);
    } catch (Exception e) {
    System.out.println(e.getMessage());
    }
    }
    private void encrypt(String inputFilePath, String outputFilePath, SecretKey serverSecretKey) {
    try {
    byte[] plainText = readFile(inputFilePath);
    Cipher cipher = Cipher.getInstance("DESede");
    cipher.init(Cipher.ENCRYPT_MODE, serverSecretKey);
    byte[] encryptedData = cipher.doFinal(plainText);
    try (FileOutputStream fos = new FileOutputStream(outputFilePath)) {
    fos.write(encryptedData);
    fos.flush();
    }
    System.out.println("Encryption successful. Encrypted text saved to: " + outputFilePath);
    } catch (Exception e) {
    System.out.println(e.getMessage());
    }
    }
    private byte[] readFile(String inputFilePath) throws Exception {
    File file = new File(inputFilePath);
    byte[] data = new byte[(int) file.length()];
    try (FileInputStream fis = new FileInputStream(file)) {
    fis.read(data);
    }
    return data;
    }
    }
  • Decryption:
    package symmetric;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.util.Base64;
    import javax.crypto.Cipher;
    import javax.crypto.KeyGenerator;
    import javax.crypto.SecretKey;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;
    public class TripleDES_Alg_Decryption extends javax.swing.JFrame {
    private int result;
    private SecretKey secretKey;
    private String keyFilePath = "/home/soft20/NetBeansProjects/TripleDES/secret.key";
    public TripleDES_Alg_Decryption() {
    initComponents();
    try {
    KeyGenerator keyGen = KeyGenerator.getInstance("DESede");
    keyGen.init(168); // 168-bit key size
    this.secretKey = keyGen.generateKey();
    saveSecretKey(this.secretKey, keyFilePath);
    } catch (Exception e) {
    System.out.println(e.getMessage());
    }
    }
    @SuppressWarnings("unchecked")
    // //GEN-BEGIN:initComponents
    private void initComponents() {
    jLabel1 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    jLabel3 = new javax.swing.JLabel();
    jTextField2 = new javax.swing.JTextField();
    jButton3 = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jButton4 = new javax.swing.JButton();
    jLabel2 = new javax.swing.JLabel();
    jButton2 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jLabel1.setText("TripleDes_Alg_Decryption");
    jButton1.setText("Choose File");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    }
    });
    jLabel3.setText("File Path");
    jButton3.setText("DECRYPT");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton3ActionPerformed(evt);
    }
    });
    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane1.setViewportView(jTextArea1);
    jButton4.setText("SecretKey");
    jButton4.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton4ActionPerformed(evt);
    }
    });
    jLabel2.setText("File Path");
    jButton2.setText("Choose File");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton2ActionPerformed(evt);
    }
    });
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(51, 51, 51)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(jButton1)
    .addGroup(layout.createSequentialGroup()
    .addGap(186, 186, 186)
    .addComponent(jButton2)))
    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    .addGroup(layout.createSequentialGroup()
    .addComponent(jLabel2)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(32, 32, 32))))
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(26, 26, 26)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(119, 119, 119)
    .addComponent(jLabel1))
    .addGroup(layout.createSequentialGroup()
    .addGap(26, 26, 26)
    .addComponent(jLabel3)
    .addGap(34, 34, 34)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(jButton3)
    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 451, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(layout.createSequentialGroup()
    .addGap(149, 149, 149)
    .addComponent(jButton4)))
    .addContainerGap(39, Short.MAX_VALUE)))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(66, 66, 66)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(jLabel2)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(18, 18, 18)
    .addComponent(jButton1)
    .addGap(75, 75, 75)
    .addComponent(jButton2)
    .addContainerGap(192, Short.MAX_VALUE))
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jLabel1)
    .addGap(142, 142, 142)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jLabel3))
    .addGap(78, 78, 78)
    .addComponent(jButton3)
    .addGap(18, 18, 18)));
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(18, 18, 18)
    .addComponent(jButton4)
    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
    );
    pack();
    }//
    //GEN-END:initComponents
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Choose a file");
    result = fileChooser.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
    File selectedFile = fileChooser.getSelectedFile();
    jTextField1.setText(selectedFile.getAbsolutePath());
    } else {
    jTextField1.setText("No File Selected ");
    }
    }//GEN-LAST:event_jButton1ActionPerformed
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Choose a file");
    result = fileChooser.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
    File selectedFile = fileChooser.getSelectedFile();
    jTextField2.setText(selectedFile.getAbsolutePath());
    } else {
    jTextField2.setText("No File Selected ");
    }
    }//GEN-LAST:event_jButton2ActionPerformed
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    String inputFilePath = jTextField1.getText();
    String outputFilePath = jTextField2.getText();
    try {
    decrypt(inputFilePath, outputFilePath, secretKey);
    JOptionPane.showMessageDialog(this, "File decrypted successfully.");
    } catch (Exception e) {
    System.out.println(e.getMessage());
    }
    }//GEN-LAST:event_jButton3ActionPerformed
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    display();
    }//GEN-LAST:event_jButton4ActionPerformed
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(() -> {
    new TripleDES_Alg_Decryption().setVisible(true);
    });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
    private void saveSecretKey(SecretKey secretKey, String keyFilePath) {
    try (FileOutputStream fos = new FileOutputStream(keyFilePath)) {
    byte[] keyBytes = secretKey.getEncoded();
    fos.write(Base64.getEncoder().encode(keyBytes));
    fos.flush();
    System.out.println("Secret key saved to: " + keyFilePath);
    } catch (Exception e) {
    JOptionPane.showMessageDialog(this, "Error saving secret key: " + e.getMessage());
    }
    }
    private void decrypt(String inputFilePath, String outputFilePath, SecretKey secretKey) {
    try {
    byte[] encryptedData = readFile(inputFilePath);
    Cipher cipher = Cipher.getInstance("DESede");
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    byte[] decryptedData = cipher.doFinal(encryptedData);
    try (FileOutputStream fos = new FileOutputStream(outputFilePath)) {
    fos.write(decryptedData);
    }
    System.out.println("Decryption complete. Decrypted data saved to " + outputFilePath);
    } catch (Exception e) {
    System.out.println(e.getMessage());
    }
    }
    private byte[] readFile(String inputFilePath) throws Exception {
    File file = new File(inputFilePath);
    byte[] data = new byte[(int) file.length()];
    try (FileInputStream fis = new FileInputStream(file)) {
    fis.read(data);
    }
    return data;
    }
    private void display() {
    try {
    byte[] publicKeyBytes = secretKey.getEncoded();
    String res = Base64.getEncoder().encodeToString(publicKeyBytes);
    jTextArea1.setText(res);
    } catch (Exception e) {
    System.out.println(e.getMessage());
    }
    }
    }
Step 1
  • To start the encryption process, select the input file path after setting up the TripleDES encryption GUI.
  • Encrypt and Decrypt data using tripledes1
  • Encrypt and Decrypt data using tripledes2
Step 2
  • The chosen file location is indicated by the selected file path that shows up in the text field.
  • Encrypt and Decrypt data using tripledes3
Step 3
  • Select the path of the 'Encrypt.txt' file to begin the encryption process.
  • Encrypt and Decrypt data using tripledes4
Step 4
  • The path of the 'Encrypt.txt' file has been selected for encryption.
  • Encrypt and Decrypt data using tripledes5
Step 5
  • The files Encrypt.txt and input.txt are chosen. When the Encrypt button is clicked, encryption is successfully finished.
  • The encrypt method reads the plaintext from the input file, encrypts it using Triple DES (DESede) with the provided serverSecretKey, and saves the encrypted data to the output file. It handles exceptions and prints a success message upon successful encryption.
  • Encrypt and Decrypt data using tripledes6
Step 6
  • To start the decryption process, select the input file path after setting up the TripleDES decryption GUI.
  • Encrypt and Decrypt data using tripledes7
  • Encrypt and Decrypt data using tripledes8
Step 7
  • The chosen file location is indicated by the selected file path that shows up in the text field.
  • Encrypt and Decrypt data using tripledes9
Step 8
  • Select the path of the 'Decrypt.txt' file to begin the decryption process.
  • Encrypt and Decrypt data using tripledes10
Step 9
  • The path of the 'Decrypt.txt' file has been selected for decryption.
  • Encrypt and Decrypt data using tripledes11
Step 10
  • The files Encrypt.txt and Decrypt.txt are chosen. When the Decrypt button is clicked, decryption is successfully finished.
  • The decrypt method uses Triple DES (DESede) to decrypt data from an encrypted file. It initializes a Cipher in decryption mode with the provided secret key and decrypts the byte array read from the input file. Finally, it writes the decrypted data to the specified output file, handling any exceptions that might occur.
  • Encrypt and Decrypt data using tripledes12
Step 11
  • Use the same secret key for both encryption and decryption to maintain consistency and ensure accurate data retrieval.
  • Encrypt and Decrypt data using tripledes13
  • Encrypt and Decrypt data using tripledes14
  • Encrypt and Decrypt data using tripledes15
Step 12
  • Encryption applies to the input text file, with the result saved in the encrypt text file. Decryption restores the original content from the decrypt text file.
  • Encrypt and Decrypt data using tripledes16
  • Encrypt and Decrypt data using tripledes17
  • Encrypt and Decrypt data using tripledes18