import javax.crypto.*;
import javax.crypto.spec.*;
import java.nio.charset.*;
import java.util.*;
public class Main {
private static final String KEY = "u12hUPtyGhg5WR3t";
public static void main(String[] args) throws Exception {
var value1 = encryptAES("Mupi.123");
var value2 = decryptAES(value1);
System.out.println(value1);
System.out.println(value2);
}
public static String encryptAES(String value) {
try {
SecretKey secretKey = new SecretKeySpec(getKeyBytes(), "AES");
IvParameterSpec iv = new IvParameterSpec(getKeyBytes());
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
byte[] encrypted = cipher.doFinal(value.getBytes());
return Base64.getEncoder().encodeToString(encrypted);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static String decryptAES(String encrypted) {
try {
SecretKey secretKey = new SecretKeySpec(getKeyBytes(), "AES");
IvParameterSpec iv = new IvParameterSpec(getKeyBytes());
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
byte[] original = cipher.doFinal(Base64.getDecoder().decode(encrypted));
return new String(original);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static byte[] getKeyBytes() {
byte[] iv = new byte[16];
return KEY.getBytes(StandardCharsets.UTF_8);
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: