看了几个都写的不好,还是自己写把
注意 PKCS7 需要加一下依赖
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
<version>1.46</version>
</dependency>
不BB废话,直上代码
import com.alibaba.fastjson.JSON;
import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.validation.constraints.NotNull;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.Security;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public class AESUtil {
private static final String AES = "AES";
static {
Security.addProvider(new BouncyCastleProvider());
}
public static void main(String[] args) throws Exception {
DecimalFormat nf = new DecimalFormat("16880000000");
Map<String, Object> data = new LinkedHashMap<>();
for (int i = 1; i <= 5; i++) {
data.put("曾特喵穷" + i, nf.format(i));
}
Map<String, Object> map = new HashMap<>();
map.put("data", data);
String wait = JSON.toJSONString(map);
System.out.println("wait => " + wait);
// 长度可以是 16