import [Link].
Cipher;
import [Link];
import [Link];
import [Link];
import [Link].Base64;
public class AESExample{
public static void main(String[] args)throws Exception{
String plaintext="Hello,World!';
SecretKey secretKey=generateAeskey()
String ciphertext=encryptAES(plaintext,secretKey);
String decryptedText=decryptAES(ciphertext,secretkey);
[Link]("Plaintext:"+plaintext);
[Link]("Ciphertext:"+ciphertext);
[Link]("Decryptedtext:"+decryptedText);
}
public static SecretKey generateAESKey()throws Exception{
KeyGenerator KeyGenerator=[Link]("AES")
[Link](256,new secureRandom());
return [Link]();
}
public static String encryptAES(String plaintext,SecretKey secretKey)throws
Exception{
Cipher cipher=[Link]("AES");
[Link](Cipher.DECRYPT_MODE,secretkey);
byte[]ciphertextByte=[Link]().decode(ciphertext);
byte[]plaintextBytes=[Link](ciphertextBytes);
return new String(plaintextBytes);
}
}