Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Simple Encryption Decryption using AES in Java

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 541
    Comment on it

    Following is Simple Encryption and Decryption using AES in Java. Data Encryption Standard (DES) is prone to brute-force attacks. It is a old way of encrypting data. It is replaced by Advanced Encryption Standard (AES).

    If you have Java 8 you can use java.util.Base64 else for previous version you can org.apache.commons.codec.binary.Base64; Download Jar from following link for previous Java versions.

    package com.app.util;
    
    import org.apache.commons.codec.binary.Base64;
    
    public class EncryptionDecryption{
    
        public static void main(String[] args) throws Exception {
            String plainText = "Chandan Sing Ahluwalia";
            System.out.println("Plain Text Before Encryption: " + plainText);
    
            String encryptedText = EncryptionDecryption.encryptContent(plainText);
            System.out.println("Encrypted Text After Encryption: " + encryptedText);
    
            String decryptedText = EncryptionDecryption.decryptContent(encryptedText);
            System.out.println("Decrypted Text After Decryption: " + decryptedText);
        }
    
        public static String encryptContent(String plainText)
                throws Exception {
            byte[] encodedBytes = Base64.encodeBase64(plainText.getBytes());
            return new String(encodedBytes);
        }
    
    
        public static String decryptContent(String encryptedText)
                throws Exception {
            byte[] decodedBytes = Base64.decodeBase64(encryptedText.getBytes());
            return new String(decodedBytes);
        }
    }
    

    Following is the output i received for above program:

    Plain Text Before Encryption: Chandan Sing Ahluwalia
    Encrypted Text After Encryption: Q2hhbmRhbiBTaW5nIEFobHV3YWxpYQ==
    Decrypted Text After Decryption: Chandan Sing Ahluwalia
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: