Running Code for Assignment String decryptedMiddlename =
decrypt(middlenameText, secretKey);
import java.util.*;
String decryptedLastname =
import javax.crypto.Cipher; decrypt(lastnameCipherText, secretKey);
import javax.crypto.KeyGenerator; System.out.println("Decrypted Middlename: " +
import javax.crypto.SecretKey; decryptedMiddlename);
import java.util.Base64; System.out.println("Decrypted Lastname: " +
decryptedLastname);
}
public class EncryptionDecryptionAES{
static Cipher cipher;
public static byte[] encrypt(String plainText, SecretKey
secretKey) throws Exception {
public static void main(String[] args) throws Exception cipher = Cipher.getInstance("AES");
{
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
String firstname = "";
byte[] plainTextByte = plainText.getBytes();
String middlename = "";
byte[] encryptedByte =
String lastname = ""; cipher.doFinal(plainTextByte);
Base64.Encoder encoder = Base64.getEncoder();
Scanner Manching=new Scanner (System.in); String encryptedText =
encoder.encodeToString(encryptedByte);
System.out.print("Enter Firstname: ");
return encryptedByte;
firstname=Manching.nextLine();
}
System.out.print("Enter Middlename: ");
public static String decrypt(byte[] cipherText,
middlename=Manching.nextLine();
SecretKey secretKey) throws Exception {
cipher.init(Cipher.DECRYPT_MODE, secretKey);
System.out.print("Enter Lastname: ");
byte[] decryptedByte = cipher.doFinal(cipherText);
lastname=Manching.nextLine();
String decryptedText = new String(decryptedByte);
return decryptedText;
SecretKey secretKey =
}
KeyGenerator.getInstance("AES").generateKey();
}
byte[] middlenameText = encrypt(middlename,
secretKey);
byte[] lastnameCipherText = encrypt(lastname,
secretKey);
System.out.println("Encrypted Middlename: " +
new String(middlenameText));
System.out.println("Encrypted Lastname: " + new
String(lastnameCipherText));