import it.uniupo.byteLib.Tools; import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; public class AES { public byte[] ctr(byte[] pt) { Cipher c; try { c = Cipher.getInstance("AES/CTR/NoPadding"); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { throw new RuntimeException(e); } KeyGenerator keyGenerator; try { keyGenerator = KeyGenerator.getInstance("AES"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } var key = keyGenerator.generateKey(); Tools.writeByteFlow(key.getEncoded(), "key"); try { c.init(Cipher.ENCRYPT_MODE, key); } catch (InvalidKeyException e) { throw new RuntimeException(e); } try { c.doFinal(pt); } catch (IllegalBlockSizeException | BadPaddingException e) { throw new RuntimeException(e); } } }