MCPcopy Index your code
hub / github.com/CDSecLab/MJXT / encrypt

Method encrypt

src/main/java/utils/AESUtil.java:16–36  ·  view source on GitHub ↗
(byte[] K_e,byte[] plaintext)

Source from the content-addressed store, hash-verified

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));

Callers 3

constructMethod · 0.95
constructMethod · 0.95
constructMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected