AES (Advanced Encryption Standard) Authentication
What is AES?
AES is known as Advanced Encryption Standard, a symmetric 128-bit block data encryption technique developed by Belgian cryptographers Joan Daemen and Vincent Rijmen.

SecretKeySpec – It is an interface used to construct secret key from byte arrays.
Cipher – Provides functionality for Encryption and Decryption

AES Code: (Encryption and Decryption)

public class AESExample {
   public static void main(String args[])
            String secretMessage = "This is a Secret Message";
            String key = "primarykey254635";
            Key secretKeySpec = new SecretKeySpec(key.getBytes(), "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
            byte[] encrypted = cipher.doFinal(secretMessage.getBytes());

            cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
            String decrypted = new String(cipher.doFinal(encrypted));
        catch(Exception e) 

In this code, We are specifying AES security and SecretKeySpec gets the key in bytes. Then Cipher (Which performs encryption and decryption) gets the type of security standard – AES and then it encrypts (Cipher.ENCRYPT_MODE) also with bytes of the key.

cipher.doFinal which Encrypts or decrypts data in a single-part operation – Conclusion of operation. After this step we are printing the encrypted message.

Then we are performing the decryption of message  with the help of SecretKeySpec and retrieve the original Message.



By Sri

Leave a Reply

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