0% found this document useful (0 votes)
18 views1 page

AES Encryption and Decryption Example

g

Uploaded by

Estrella Rosete
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)
18 views1 page

AES Encryption and Decryption Example

g

Uploaded by

Estrella Rosete
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

Running Code for Assignment String decryptedMiddlename =

decrypt(middlenameText, secretKey);
import [Link].*;
String decryptedLastname =
import [Link]; decrypt(lastnameCipherText, secretKey);
import [Link]; [Link]("Decrypted Middlename: " +
import [Link]; decryptedMiddlename);

import [Link].Base64; [Link]("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 = [Link]("AES");


{
[Link](Cipher.ENCRYPT_MODE, secretKey);
String firstname = "";
byte[] plainTextByte = [Link]();
String middlename = "";
byte[] encryptedByte =
String lastname = ""; [Link](plainTextByte);

[Link] encoder = [Link]();

Scanner Manching=new Scanner ([Link]); String encryptedText =


[Link](encryptedByte);
[Link]("Enter Firstname: ");
return encryptedByte;
firstname=[Link]();
}

[Link]("Enter Middlename: ");


public static String decrypt(byte[] cipherText,
middlename=[Link]();
SecretKey secretKey) throws Exception {

[Link](Cipher.DECRYPT_MODE, secretKey);
[Link]("Enter Lastname: ");
byte[] decryptedByte = [Link](cipherText);
lastname=[Link]();
String decryptedText = new String(decryptedByte);

return decryptedText;
SecretKey secretKey =
}
[Link]("AES").generateKey();
}
byte[] middlenameText = encrypt(middlename,
secretKey);

byte[] lastnameCipherText = encrypt(lastname,


secretKey);

[Link]("Encrypted Middlename: " +


new String(middlenameText));

[Link]("Encrypted Lastname: " + new


String(lastnameCipherText));

You might also like