public class AES3 {

public SecretKeySpec secretKey;
public byte[] key;

public void setKey(String myKey)
{
MessageDigest sha = null;
try {
key = myKey.getBytes(“UTF-8”);
sha = MessageDigest.getInstance(“SHA-1”);
key = sha.digest(key);
key = Arrays.copyOf(key, 16);
secretKey = new SecretKeySpec(key, “AES”);
System.out.println(“secret Key –> “+ secretKey);
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}

public String encrypt(String strToEncrypt, String secret)
{
try
{
this.setKey(secret);
Cipher cipher = Cipher.getInstance(“AES/ECB/PKCS5Padding”);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
return Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes(StandardCharsets.UTF_8)));

} 
catch (Exception e) 
{
    System.out.println("Error while encrypting: " + e.toString());
}
return null;

}

public String decrypt(String strToDecrypt, String secret)
{
try
{
this.setKey(secret);
Cipher cipher = Cipher.getInstance(“AES/ECB/PKCS5PADDING”);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte []base64S = Base64.getDecoder().decode(strToDecrypt.getBytes(StandardCharsets.UTF_8));
String fs = new String(cipher.doFinal(base64S));
return fs;
}
catch (Exception e)
{
System.out.println(“Error while decrypting: ” + e.toString());
}
return null;
}
public static void main(String[] args) {
String orginalString=”Hellllooooooooo”;

AES3 aES3 = new AES3();
String encryptString = aES3.encrypt(orginalString,”aeiou”);
String decryptString = aES3.decrypt(encryptString,”aeiou”);

System.out.println(orginalString);
System.out.println(encryptString);
System.out.println(decryptString);
}

}