加密
java.util.Base64;
javax.crypto.Cipher;
javax.crypto.spec.SecretKeySpec;
// 入参:data(String)、seed(String)
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
SecretKeySpec secretKeySpec;
byte[] bytes;
bytes = seed.getBytes("utf-8");
secretKeySpec = new SecretKeySpec(bytes, "AES");
cipher.init(1, secretKeySpec);
return Base64.getEncoder().encodeToString(cipher.doFinal(data.getBytes("utf-8")));
解密
java.util.Base64;
javax.crypto.spec.SecretKeySpec;
javax.crypto.Cipher;
/*
入参:
data
seed
*/
byte[] bytes;
SecretKeySpec secretKeySpec;
bytes = seed.getBytes("utf-8");
secretKeySpec = new SecretKeySpec(bytes, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(2, secretKeySpec);
return new String(cipher.doFinal(Base64.getDecoder().decode(data)), "utf-8");