0% found this document useful (0 votes)
36 views3 pages

Advanced Encryption Standard (AES) Algorithm (URL Encryption)

1. The document describes the Advanced Encryption Standard (AES) algorithm and its use for encrypting URLs. 2. AES is based on substitution-permutation networks and uses a fixed block size of 128 bits and keys of 128, 192, or 256 bits. 3. The code provided implements AES to encrypt and decrypt a sample URL using a 256-bit key.

Uploaded by

Paper Art
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Advanced Encryption Standard (AES) Algorithm (URL Encryption)

1. The document describes the Advanced Encryption Standard (AES) algorithm and its use for encrypting URLs. 2. AES is based on substitution-permutation networks and uses a fixed block size of 128 bits and keys of 128, 192, or 256 bits. 3. The code provided implements AES to encrypt and decrypt a sample URL using a 256-bit key.

Uploaded by

Paper Art
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

KRITHIK CS 710720205023

EX.NO: 4
Advanced Encryption Standard (AES) Algorithm
DATE: ( URL Encryption )
AIM:

ALGORITHM:
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 of 128 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 {

IT8761
KRITHIK CS 710720205023

setKey(secret);
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
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) {
final String secretKey = "gooooogle";
String originalString = "bard.google.com";
String encryptedString = AES.encrypt(originalString, secretKey);
String decryptedString = AES.decrypt(encryptedString, secretKey);
System.out.println("------------| 20IT023 |------------");
System.out.println("URL Encryption Using AES Algorithm");
System.out.println("Original URL : " + originalString);
System.out.println("Encrypted URL : " + encryptedString);
System.out.println("Decrypted URL : " + decryptedString); } }

OUTPUT:

RESULT:

IT8761
KRITHIK CS 710720205023

IT8761

You might also like