@Test public void testAESEncrypt(){ String input = "hello world"; String result = EncryptUtil.encrypt(input); Assert.assertEquals("4stv/RRleOtvie/8SLHmXA==", result); }
public static String encrypt(String strToEncrypt) { try { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); final SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); final String encryptedString = Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes( StandardCharsets.UTF_8))); return encryptedString; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
EncryptUtil { public static String encrypt(String strToEncrypt) { try { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); final SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); final String encryptedString = Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes( StandardCharsets.UTF_8))); return encryptedString; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } }
EncryptUtil { public static String encrypt(String strToEncrypt) { try { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); final SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); final String encryptedString = Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes( StandardCharsets.UTF_8))); return encryptedString; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }  }
EncryptUtil { public static String encrypt(String strToEncrypt) { try { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); final SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); final String encryptedString = Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes( StandardCharsets.UTF_8))); return encryptedString; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }  static String encrypt(String strToEncrypt); static String decrypt(String strToDecrypt); static void main(String[] args); }
EncryptUtil { public static String encrypt(String strToEncrypt) { try { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); final SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); final String encryptedString = Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes( StandardCharsets.UTF_8))); return encryptedString; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }  static String encrypt(String strToEncrypt); static String decrypt(String strToDecrypt); static void main(String[] args);  }