[测评系统]--测评系统核心代码库
吴祝攀
2024-06-14 499b1d27da156ddd25c7adb58a5601805d8149fe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.ots.project.tool.exam;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
 
public class DecryptUtil {
    public static byte[] AES_CBC_Decrypt(byte[] data, byte[] key, byte[] iv) throws Exception{
        Cipher cipher = getCipher(Cipher.DECRYPT_MODE, key, iv);
        return cipher.doFinal(data);
    }
    private static Cipher getCipher(int mode, byte[] key, byte[] iv) throws Exception{
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        
        
        SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
        cipher.init(mode, secretKeySpec, new IvParameterSpec(iv));
        return cipher;
    }
    public static void main(String[] args) throws Exception {
        
        
        byte[] bytes = "db2139561c9fe068".getBytes();
        String base64Str = Base64.encodeBase64String(bytes);
        System.out.println(base64Str);
        String crypto = "34439a96e68b129093105b67de81c0fc";
        byte[] data = Hex.decodeHex(crypto.toCharArray());
        byte[] s = AES_CBC_Decrypt(data, bytes, bytes);
        System.out.println(new String(s));
    }
}