Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
DES Encryption Program Code Using Java JFrame

DES Encryption Program Code Using Java JFrame

Posted on August 16, 2024August 16, 2024 By Updategadh No Comments on DES Encryption Program Code Using Java JFrame

DES Encryption Program Using Java JFrame and Swing

A simple Java Swing application that implements DES (Data Encryption Standard) encryption and decryption using javax.crypto libraries. This program uses JFrame for the GUI.

Table of Contents

  • DES Encryption Program Using Java JFrame and Swing
    • Explanation:
    • DES Encryption Program Using JFrame and Swing
    • How to Run the Program:
    • Steps
    • Sample Output
    • Screenshots (Conceptual)
    • Important Notes:
    • Considerations:
encryption program
encryption program

Explanation:

  1. GUI Components:
  • The application consists of a simple Swing GUI with fields to input the text, key, and an output area to display the encrypted or decrypted text.
  • JTextField is used for inputting the text and key.
  • JTextArea is used for displaying the output.
  • Two buttons (JButton) are provided for encryption and decryption.
  1. Encryption and Decryption:
  • The encrypt method uses Cipher to encrypt the input text with the provided DES key. The encrypted data is then encoded using Base64 to make it readable.
  • The decrypt method performs the reverse process, decoding the Base64-encoded string and decrypting it back to its original form.
  1. Key Validation:
  • The DES key must be exactly 8 characters long, which is a requirement for DES encryption. The application checks this and prompts the user if the key length is invalid.
https://updategadh.com/how-to/career-in-data-science/

DES Encryption Program Using JFrame and Swing

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Base64;

public class DESEncryptionGUI extends JFrame {

    private JTextField inputTextField;
    private JTextField keyTextField;
    private JTextArea outputTextArea;
    private JButton encryptButton;
    private JButton decryptButton;

    private SecretKey secretKey;

    public DESEncryptionGUI() {
        setTitle("DES Encryption/Decryption");
        setSize(400, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(5, 2));

        panel.add(new JLabel("Input Text:"));
        inputTextField = new JTextField();
        panel.add(inputTextField);

        panel.add(new JLabel("Key (8 characters):"));
        keyTextField = new JTextField();
        panel.add(keyTextField);

        panel.add(new JLabel("Output:"));
        outputTextArea = new JTextArea();
        outputTextArea.setLineWrap(true);
        outputTextArea.setWrapStyleWord(true);
        outputTextArea.setEditable(false);
        panel.add(new JScrollPane(outputTextArea));

        encryptButton = new JButton("Encrypt");
        decryptButton = new JButton("Decrypt");

        panel.add(encryptButton);
        panel.add(decryptButton);

        add(panel);

        // Action listener for Encrypt button
        encryptButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    String inputText = inputTextField.getText();
                    String key = keyTextField.getText();
                    if (key.length() != 8) {
                        JOptionPane.showMessageDialog(null, "Key must be 8 characters long.");
                        return;
                    }
                    secretKey = new SecretKeySpec(key.getBytes(), "DES");
                    String encryptedText = encrypt(inputText, secretKey);
                    outputTextArea.setText("Encrypted: " + encryptedText);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });

        // Action listener for Decrypt button
        decryptButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    String inputText = inputTextField.getText();
                    String key = keyTextField.getText();
                    if (key.length() != 8) {
                        JOptionPane.showMessageDialog(null, "Key must be 8 characters long.");
                        return;
                    }
                    secretKey = new SecretKeySpec(key.getBytes(), "DES");
                    String decryptedText = decrypt(inputText, secretKey);
                    outputTextArea.setText("Decrypted: " + decryptedText);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
    }

    public String encrypt(String strToEncrypt, SecretKey secretKey) throws Exception {
        Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        byte[] encryptedBytes = cipher.doFinal(strToEncrypt.getBytes("UTF-8"));
        return Base64.getEncoder().encodeToString(encryptedBytes);
    }

    public String decrypt(String strToDecrypt, SecretKey secretKey) throws Exception {
        Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, secretKey);
        byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(strToDecrypt));
        return new String(decryptedBytes, "UTF-8");
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new DESEncryptionGUI().setVisible(true);
            }
        });
    }
}

How to Run the Program:

  1. Copy the code into a Java IDE or text editor.
  2. Compile and run the program.
  3. Input text and a key in the provided fields, then click the “Encrypt” button to see the encrypted text.
  4. To decrypt, paste the encrypted text back into the input field and use the same key, then click “Decrypt” to see the original text.

Final year Java Projects :- Click Here

Steps

  1. Launching the Program:
  • When you run the DESEncryptionGUI class, a window (JFrame) will appear with the following fields and buttons:
    • Input Text: A text field where you enter the text to be encrypted or decrypted.
    • Key (8 characters): A text field where you enter the DES key. The key must be exactly 8 characters long.
    • Output: A text area where the result (encrypted or decrypted text) is displayed.
    • Encrypt Button: Clicking this button will encrypt the text using the provided key.
    • Decrypt Button: Clicking this button will decrypt the text using the provided key.
https://updategadh.com/jsp-javaj2ee/hospital-management-system-java/
  1. Example Scenario:
  • Input Text: HelloWorld
  • Key (8 characters): MySecret
  • Click on “Encrypt” Button:
    • The output area will display the encrypted text (Base64 encoded).
  • Copy the Encrypted Text from the output area to the input field.
  • Click on “Decrypt” Button:
    • The output area will display the original text HelloWorld.

Sample Output

  1. Initial Screen:
  • When the program starts, the fields will be empty.
  1. After Encryption: Input Text: HelloWorld
    Key (8 characters): MySecret Output:
   Encrypted: +kthM2BCQcU=

This shows the Base64-encoded encrypted text.

  1. After Decryption:
  • Copy the encrypted text (+kthM2BCQcU=) back into the input field and use the same key MySecret.
  • After clicking the “Decrypt” button, the output will show:
   Decrypted: HelloWorld

Top JSP PROJECTS :- Click here

Screenshots (Conceptual)

If you were to see this in a graphical interface:

  1. Before Encryption:
   Input Text:      [HelloWorld]
   Key (8 chars):   [MySecret]
   Output:          [                    ]

(Click “Encrypt”)

  • Complete Python Course : Click here
  • Free Notes :- Click here
  • New Project :-https://www.youtube.com/@Decodeit2
  • How to setup this Project Complete video – Click here
  1. After Encryption:
   Input Text:      [HelloWorld]
   Key (8 chars):   [MySecret]
   Output:          [Encrypted: +kthM2BCQcU=]
  1. After Decryption:
   Input Text:      [+kthM2BCQcU=]
   Key (8 chars):   [MySecret]
   Output:          [Decrypted: HelloWorld]

Important Notes:

  • Security: DES is outdated and insecure for modern applications. Consider using AES for stronger encryption.
  • GUI Experience: This example shows how Swing can be used to create interactive Java applications, making it suitable for learning and small-scale projects.

Considerations:

  • DES is considered insecure by today’s standards for cryptography. For actual encryption needs, consider using more secure algorithms like AES.
  • The code provided here is meant for educational purposes and should not be used in production systems.

encryption program
how to make an encryption program in python
aes encryption program
string encryption program in java
encryption program meaning
caesar cipher encryption program in c
aes encryption program in java
what was different about zimmermann encryption program
des encryption program in java
encryption program app
encryption audit program
encryption algorithm program in c++
aes encryption program in c
aes encryption program in python
an encryption program
best encryption program
blowfish encryption program
binary encryption program in c++

Post Views: 700
code Snippets Tags:caesar cipher encryption and decryption program, data encryption, decryption, disk encryption, encryption, encryption and decryption programming, encryption programs, encryption software, encryption tools, Free Project, full disk encryption, hard drive encryption, hardware encryption, Java, java and mysql, java encryption, java encryption and decryption, java encryption and decryption program, java encryption and decryption project, java encryption and decryption tutorial, JavaScript, PHP And MYSQL, program, python encryption

Post navigation

Previous Post: Finding the Sum of Digits: Multi language Java, Python, Js
Next Post: How to Get Started with Ethical Hacking and Cybersecurity

More Related Articles

Hospital Billing Management System in Python free code - Hospital billing Hospital Billing Management System in Python free code code Snippets
Bill Management System in Python Free Source Code - Bill Management Bill Management System in Python Free Source Code code Snippets
Create a Stunning Word Cloud with Python: A Step-by-Step Guide - Stunning Word Cloud with Python Create a Stunning Word Cloud with Python: A Step-by-Step Guide code Snippets

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. News Portal Project in PHP and MySql Free Source Code
  5. Flipkart Clone using PHP And MYSQL Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme