package org.example;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class App {

    private static final byte[] key = "abcdefghijklmnop".getBytes();
    private static final byte[] iv = "0123456789012345".getBytes();

    private byte[] encrypt(byte[] input) throws Exception {
        SecretKeySpec key = new SecretKeySpec(App.key, "AES");
        IvParameterSpec iv = new IvParameterSpec(App.iv);

        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, key, iv);

        return cipher.doFinal(input);
    }

    private byte[] decrypt(byte[] input) throws Exception {
        SecretKeySpec key = new SecretKeySpec(App.key, "AES");
        IvParameterSpec iv = new IvParameterSpec(App.iv);

        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, key, iv);

        return cipher.doFinal(input);
    }

    public static void main(String... args) throws Exception {
        App app = new App();

        String original = "your name is";
        byte[] input = original.getBytes(StandardCharsets.UTF_8);
        byte[] encrpyted = app.encrypt(input);
        byte[] decrpypted = app.decrypt(encrpyted);
        String result = new String(decrpypted, StandardCharsets.UTF_8);

        System.out.println(String.format(" original: '%s'", original));
        System.out.println(String.format("encrypted: '%s'", Base64.getEncoder().encodeToString(encrpyted)));
        System.out.println(String.format("decrypted: '%s'", Base64.getEncoder().encodeToString(decrpypted)));
        System.out.println(String.format("   result: '%s'", result));
        System.out.println(String.format("            123456789 123456789 123456789 123456789"));

        int loop = 100000;
        byte[] headOfReturns = new byte[loop];
        long from = System.currentTimeMillis();
        for (int i = 0; i < loop; i++) {
            byte[] ret = app.encrypt(String.format("hoge-%d", i).getBytes(StandardCharsets.UTF_8));
            headOfReturns[i] = ret[0];
        }
        long to = System.currentTimeMillis();

        System.out.println();
        System.out.println(String.format("%d times, elapsed: %d msec,\nreturns: %s", loop, to - from, Base64.getEncoder().encodeToString(headOfReturns)));
    }
}

@@ -1134,24 +1134,38 @@
 new App();%0A%0A
+        %7B%0A    
         Stri
@@ -1198,24 +1198,28 @@
 s%22;%0A        
+ 
+   
 byte%5B%5D input
@@ -1268,24 +1268,28 @@
 8);%0A        
+    
 byte%5B%5D encrp
@@ -1319,24 +1319,28 @@
 t);%0A        
+ 
+   
 byte%5B%5D decrp
@@ -1371,16 +1371,20 @@
 pyted);%0A
+    
         
@@ -1448,32 +1448,36 @@
 TF_8);%0A%0A        
+    
 System.out.print
@@ -1520,24 +1520,28 @@
 original));%0A
+    
         Syst
@@ -1637,32 +1637,36 @@
 ted)));%0A        
+    
 System.out.print
@@ -1751,32 +1751,36 @@
 ted)));%0A        
+   
+ 
 System.out.print
@@ -1821,24 +1821,28 @@
 , result));%0A
+    
         Syst
@@ -1926,16 +1926,26 @@
 6789%22));
+%0A        %7D
 %0A%0A      
@@ -1965,16 +1965,31 @@
 100000;%0A
+%0A        %7B%0A    
         
@@ -2031,24 +2031,28 @@
 p%5D;%0A        
+    
 long from = 
@@ -2087,16 +2087,20 @@
         
+    
 for (int
@@ -2124,16 +2124,20 @@
  i++) %7B%0A
+    
         
@@ -2240,16 +2240,20 @@
         
+   
+ 
 headOfRe
@@ -2279,18 +2279,26 @@
         
-%7D%0A
+    %7D%0A    
         
@@ -2336,32 +2336,36 @@
 lis();%0A%0A        
+    
 System.out.print
@@ -2366,24 +2366,28 @@
 .println();%0A
+    
         Syst
@@ -2525,20 +2525,864 @@
 Returns)));%0A
+        %7D%0A        %7B%0A            SecretKeySpec key = new SecretKeySpec(App.key, %22AES%22);%0A            IvParameterSpec iv = new IvParameterSpec(App.iv);%0A%0A            Cipher cipher = Cipher.getInstance(%22AES/CBC/PKCS5Padding%22);%0A            cipher.init(Cipher.ENCRYPT_MODE, key, iv);%0A%0A            byte%5B%5D headOfReturns = new byte%5Bloop%5D;%0A            long from = System.currentTimeMillis();%0A            for (int i = 0; i %3C loop; i++) %7B%0A                byte%5B%5D ret = cipher.doFinal(String.format(%22hoge-%25d%22, i).getBytes(StandardCharsets.UTF_8));%0A                headOfReturns%5Bi%5D = ret%5B0%5D;%0A            %7D%0A            long to = System.currentTimeMillis();%0A%0A            System.out.println();%0A            System.out.println(String.format(%22%25d times, elapsed: %25d msec,%5Cnreturns: %25s%22, loop, to - from, Base64.getEncoder().encodeToString(headOfReturns)));%0A        %7D%0A
     %7D%0A%7D%0A

Add micro benchmark of java crypto framework