Encrypt String Using AES Algorithm
Encrypt a String using AES algorithm.
Javadoc available at https://www.javatapas.com/docs/javatapas/string/EncryptString.html
public static byte[] encryptString(String inStr) throws NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, NoSuchPaddingException, BadPaddingException {
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(256);
SecretKey secretKey = keyGenerator.generateKey();
byte[] raw = secretKey.getEncoded();
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encrypted = cipher.doFinal(inStr.getBytes());
return encrypted;
}