Commit a55e27c4 authored by 以墨为白's avatar 以墨为白 🎧

加密优化

parent 54656191
......@@ -5,6 +5,7 @@ import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
......@@ -135,13 +136,34 @@ public class EncryptUtil {
return keyGeneratorES(res, DES, key, keySizeDES, false);
}
/**
* 使用AES加密算法经行加密(可逆)
*
* @param data 需要加密的密文
* @param password 秘钥
*/
public String AESEncode(String data, String password) {
byte[] key = password.getBytes();//16字节密钥
byte[] iv = "1234567890123456" .getBytes();//iv
SecretKey secretKey = new SecretKeySpec(key, "AES");
try {
IvParameterSpec ivSpec = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");//加密算法/模式/填充方式
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec);
byte[] encrypted = cipher.doFinal(data.getBytes());//密文字节数组
return Base64.encode(encrypted);
} catch (Exception e) {
return null;
}
}
/**
* 使用AES加密算法经行加密(可逆)
*
* @param res 需要加密的密文
* @param key 秘钥
*/
public String AESEncode(String res, String key) {
public String AESEncode1(String res, String key) {
return keyGeneratorES(res, AES, key, keySizeAES, true);
}
......
......@@ -5,5 +5,5 @@ public class SignatureUtil {
public static String TIMESTAMP = "x-szpt-timestamp";
public static String NONCE = "x-szpt-nonce";
public static String APPID = "x-szpt-appid";
public static String DEPT_CODE = "x-szpt-dept_code";
public static String DEPT_CODE = "x-szpt-dept-code";
}
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