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

AESExample.java

The document presents a Java program that demonstrates AES encryption and decryption. It includes methods for generating a secret key, encrypting plaintext, and decrypting ciphertext. However, there are several syntax errors and incorrect method calls that need to be addressed for the code to function properly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

AESExample.java

The document presents a Java program that demonstrates AES encryption and decryption. It includes methods for generating a secret key, encrypting plaintext, and decrypting ciphertext. However, there are several syntax errors and incorrect method calls that need to be addressed for the code to function properly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import javax.crypto.

Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.security.SecureRandom;
import java.utill.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);
System.out.printin("Plaintext:"+plaintext);
System.out.printin("Ciphertext:"+ciphertext);
System.out.printin("Decryptedtext:"+decryptedText);
}
public static SecretKey generateAESKey()throws Exception{
KeyGenerator KeyGenerator=KeyGenerator.getinstance("AES")
KeyGenerator.init(256,new secureRandom());
return KeyGenerator.generateKey();
}
public static String encryptAES(String plaintext,SecretKey secretKey)throws
Exception{
Cipher cipher=Cipher.getinstance("AES");
cipher.init(Cipher.DECRYPT_MODE,secretkey);
byte[]ciphertextByte=Base64.getDecoder().decode(ciphertext);
byte[]plaintextBytes=cipher.doFinall(ciphertextBytes);
return new String(plaintextBytes);
}
}

You might also like