MCPcopy Create free account
hub / github.com/CDSecLab/MJXT / AESUtil

Class AESUtil

src/main/java/utils/AESUtil.java:14–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12import java.security.NoSuchAlgorithmException;
13
14public class AESUtil {
15 public static final String InitVector = "EncDecInitVector";
16 public static byte[] encrypt(byte[] K_e,byte[] plaintext){
17 try{
18 IvParameterSpec iv = new IvParameterSpec(InitVector.getBytes(StandardCharsets.UTF_8));
19 SecretKeySpec secretKeySpec = new SecretKeySpec(K_e, "AES");
20 Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
21 cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec,iv);
22 return cipher.doFinal(plaintext);
23 } catch (InvalidAlgorithmParameterException e) {
24 throw new RuntimeException(e);
25 } catch (NoSuchPaddingException e) {
26 throw new RuntimeException(e);
27 } catch (IllegalBlockSizeException e) {
28 throw new RuntimeException(e);
29 } catch (NoSuchAlgorithmException e) {
30 throw new RuntimeException(e);
31 } catch (BadPaddingException e) {
32 throw new RuntimeException(e);
33 } catch (InvalidKeyException e) {
34 throw new RuntimeException(e);
35 }
36 }
37
38 public static byte[] decrypt(byte[] K_e,byte[] ciphertext) {
39 IvParameterSpec iv = new IvParameterSpec(InitVector.getBytes(StandardCharsets.UTF_8));
40 try {
41 SecretKeySpec secretKeySpec = new SecretKeySpec(K_e, "AES");
42 Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
43 cipher.init(Cipher.DECRYPT_MODE, secretKeySpec,iv);
44 byte[] res = cipher.doFinal(ciphertext);
45 return res;
46 } catch (Exception e){
47
48 }
49 return null;
50 }
51}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected