0% found this document useful (0 votes)
4 views

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 views

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy