0% found this document useful (0 votes)
7 views

AESalgorithm

The document describes an AES encryption algorithm program written in Java. The program takes a URL as input, encrypts it using AES with a secret key, and then decrypts the encrypted URL back to original. AES has a fixed block size of 128 bits and supports key sizes of 128, 192, and 256 bits. It operates on a 4x4 array of bytes and uses a substitution-permutation network, unlike DES. The program successfully encrypts and decrypts a sample URL.

Uploaded by

Saraths's Cinema
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

AESalgorithm

The document describes an AES encryption algorithm program written in Java. The program takes a URL as input, encrypts it using AES with a secret key, and then decrypts the encrypted URL back to original. AES has a fixed block size of 128 bits and supports key sizes of 128, 192, and 256 bits. It operates on a 4x4 array of bytes and uses a substitution-permutation network, unlike DES. The program successfully encrypts and decrypts a sample URL.

Uploaded by

Saraths's Cinema
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

K.

RAMAKRISHNAN COLLEGE OF TECHNOLOGY

Ex.No : 4 AES ALGORITHM


Date :

Objective :

To apply Advanced Encryption Standard (AES) Algorithm for a practical application like URL
Encryption.

Procedure :

1. . AES is based on a design principle known as a substitution–permutation.


2. AES does not use a Feistel network like DES, it uses variant of Rijndael.
3. It has a fixed block size of128 bits, and a key size of 128, 192, or 256 bits.
4. AES operates on a 4 × 4 column-major order array of bytes, termed the state

Program:

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class AES
{
private static SecretKeySpec secretKey;
private static byte[] key;
public static void setKey(String myKey) {
MessageDigest sha = null;
try {
key = myKey.getBytes("UTF-8");
sha = MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
key= Arrays.copyOf(key, 16);
secretKey= new SecretKeySpec(key, "AES");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public static String encrypt(String strToEncrypt, String secret) {
try {
setKey(secret);
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
K.RAMAKRISHNAN COLLEGE OF TECHNOLOGY

cipher.init(Cipher.ENCRYPT_MODE, secretKey);
return Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes
("UTF-8")));
} catch (Exception e) {
System.out.println("Error while encrypting: " + e.toString());
}
return null;
}
public static String decrypt(String strToDecrypt, String secret) {
try {
setKey(secret);
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt)));
} catch (Exception e) {
System.out.println("Error while decrypting: " + e.toString());
}
return null;
}
public static void main(String[] args) {
System.out.println("Enter the secret key: ");
String secretKey= System.console().readLine();
System.out.println("Enter the original URL: ");
String originalString= System.console().readLine();
String encryptedString = AES.encrypt(originalString, secretKey);
String decryptedString = AES.decrypt(encryptedString, secretKey);
System.out.println("URL Encryption Using AES Algorithm\n ----------");
System.out.println("Original URL : " + originalString);
System.out.println("Encrypted URL : " + encryptedString);
System.out.println("Decrypted URL : " + decryptedString);
}
}

Output:
K.RAMAKRISHNAN COLLEGE OF TECHNOLOGY

Application :

1. The Advanced Encryption Standard (AES) is a widely used symmetric encryption algorithm that
ensures secure communication and data protection.
2. AES is commonly used to encrypt sensitive data stored on computer systems, databases, and
storage devices.
3. AES encryption is integrated into database management systems to encrypt sensitive data
stored in databases.
4. AES is used in DRM systems to encrypt multimedia content such as videos, music, and
ebooks.

Conclusion :

Thus,the java program for applying Advanced EncryptionStandard (AES) Algorithm for a
practical application of URL encryption is written and executed successfully.
K.RAMAKRISHNAN COLLEGE OF TECHNOLOGY

You might also like