· 4 years ago · Apr 14, 2021, 08:56 AM
1package de.directservices.crypto;
2
3import java.util.Base64;
4
5import javax.crypto.Cipher;
6import javax.crypto.spec.IvParameterSpec;
7import javax.crypto.spec.SecretKeySpec;
8
9public class Decrypt {
10
11 private static final String TRANSFORMATION = "AES/CBC/PKCS5Padding";
12 private static final String ALGORITHM = "AES";
13
14 public static String decrypt(String key, String cryptedText) throws Exception {
15
16 byte[] iv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
17 IvParameterSpec ivspec = new IvParameterSpec(iv);
18
19 SecretKeySpec secretKey = new SecretKeySpec(Base64.getDecoder().decode(key), ALGORITHM);
20
21 Cipher cipher = Cipher.getInstance(TRANSFORMATION);
22 cipher.init(Cipher.DECRYPT_MODE, secretKey, ivspec);
23 return new String(cipher.doFinal(Base64.getDecoder().decode(cryptedText)));
24 }
25}
26