You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
877 B

package com.project.receivedemo.utils;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
public class SfDecryptUtil {
private static final byte[] IV_BYTES = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
public static byte[] decrypt(String encryptedData, String secretKey) throws Exception {
// 顺丰推送的密文可能是 Base64 编码的字符串
byte[] decode = Base64.getDecoder().decode(encryptedData);
SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes("UTF-8"), "AES");
IvParameterSpec ivSpec = new IvParameterSpec(IV_BYTES);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
return cipher.doFinal(decode);
}
}