Commit 4ee35eb2 by yangyang

海南单点登录

parent c0007805
......@@ -5,6 +5,8 @@ import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* AES 128bit 加密解密工具类
......@@ -14,11 +16,12 @@ import javax.crypto.spec.SecretKeySpec;
public class AesEncryptUtil {
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
private static String today = simpleDateFormat.format(new Date());
//使用AES-128-CBC加密模式,key需要为16位,key和iv可以相同!
private static String KEY = "maplogin20200416";
private static String KEY = "maplogin"+ today;
private static String IV = "map_vues20200416";
private static String IV = "map_vues"+ today;
/**
......@@ -31,8 +34,7 @@ public class AesEncryptUtil {
*/
public static String encrypt(String data, String key, String iv) throws Exception {
try {
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");//"算法/模式/补码方式"NoPadding PkcsPadding
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");//"算法/模式/补码方式"NoPadding PkcsPadding
int blockSize = cipher.getBlockSize();
byte[] dataBytes = data.getBytes();
......@@ -68,9 +70,10 @@ public class AesEncryptUtil {
*/
public static String desEncrypt(String data, String key, String iv) throws Exception {
try {
data = data.replaceAll(" ","+");
byte[] encrypted1 = new Base64().decode(data);
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
......@@ -85,6 +88,8 @@ public class AesEncryptUtil {
}
}
/**
* 使用默认的key和iv加密
* @param data
......@@ -112,19 +117,15 @@ public class AesEncryptUtil {
*/
public static void main(String args[]) throws Exception {
String test1 = "1111111111000000";
String test1 = "150000000000000000";
String test =new String(test1.getBytes(),"UTF-8");
String data = null;
String key = KEY;
String iv = IV;
// /g2wzfqvMOeazgtsUVbq1kmJawROa6mcRAzwG1/GeJ4=
data = encrypt(test, key, iv);
System.out.println("数据:"+test);
System.out.println("加密:"+data);
String jiemi =desEncrypt(data, key, iv).trim();
System.out.println("解密:"+jiemi);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment