import [Link].
Cipher;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].Base64;
public class Rijndael {
public static void main(String[] args) throws Exception {
String plainText = "Hello, World!";
[Link]("Plain Text: " + plainText);
SecretKey secretKey = generateKey();
[Link]("Secret Key: " + bytesToHex([Link]()));
String encryptedText = encrypt(plainText, secretKey);
[Link]("Encrypted Text: " + encryptedText);
String decryptedText = decrypt(encryptedText, secretKey);
[Link]("Decrypted Text: " + decryptedText);
private static SecretKey generateKey() throws NoSuchAlgorithmException {
KeyGenerator keyGen = [Link]("AES");
[Link](128);
return [Link]();
private static String encrypt(String plainText, SecretKey secretKey) throws Exception {
Cipher cipher = [Link]("AES");
[Link](Cipher.ENCRYPT_MODE, secretKey);
byte[] encryptedBytes = [Link]([Link](StandardCharsets.UTF_8));
return [Link]().encodeToString(encryptedBytes);
private static String decrypt(String encryptedText, SecretKey secretKey) throws Exception {
Cipher cipher = [Link]("AES");
[Link](Cipher.DECRYPT_MODE, secretKey);
byte[] encryptedBytes = [Link]().decode(encryptedText);
byte[] decryptedBytes = [Link](encryptedBytes);
return new String(decryptedBytes, StandardCharsets.UTF_8);
private static String bytesToHex(byte[] bytes) {
StringBuilder hexString = new StringBuilder();
for (byte b : bytes) {
String hex = [Link](0xff & b);
if ([Link]() == 1) [Link]('0');
[Link](hex);
}
return [Link]();