Commit 47202569 by yangyang

海南加密解密处理

parent ec3f3d9e
......@@ -5,8 +5,11 @@ import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* AES 128bit 加密解密工具类
......@@ -34,7 +37,8 @@ public class AesEncryptUtil {
*/
public static String encrypt(String data, String key, String iv) throws Exception {
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");//"算法/模式/补码方式"NoPadding PkcsPadding
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");//"算法/模式/补码方式"NoPadding PkcsPadding
int blockSize = cipher.getBlockSize();
byte[] dataBytes = data.getBytes();
......@@ -72,8 +76,7 @@ public class AesEncryptUtil {
try {
data = data.replaceAll(" ","+");
byte[] encrypted1 = new Base64().decode(data);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
......@@ -84,7 +87,7 @@ public class AesEncryptUtil {
return originalString;
} catch (Exception e) {
e.printStackTrace();
return null;
return "解密失败";
}
}
......@@ -110,22 +113,31 @@ public class AesEncryptUtil {
return desEncrypt(data, KEY, IV);
}
public static Map<String, Object> getMap(Integer status, String msg) {
Map<String, Object> map = new HashMap<>();
map.put("code", status);
map.put("msg", msg);
return map;
}
/**
* 测试
*/
public static void main(String args[]) throws Exception {
String test1 = "460000000000000000";
String test1 = "430000000000000000";
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