Commit c0b405bf by 罗长华

使用java.util.Base64替换sun.misc.BASE64Decoder和sun.misc.BASE64Encode

parent 62996f9f
package com.wecloud.utils;
import io.geekidea.springbootplus.framework.common.exception.BusinessException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
......@@ -30,7 +30,8 @@ public class AesUtil {
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
// 此处使用BASE64做转码功能,同时能起到2次加密的作用。
return new BASE64Encoder().encode(encrypted);
Base64.Encoder encoder = Base64.getEncoder();
return encoder.encodeToString(encrypted);
} catch (Exception e) {
throw new BusinessException("系统异常,稍后重试");
}
......@@ -48,10 +49,11 @@ public class AesUtil {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] encrypted1 = new BASE64Decoder().decodeBuffer(sSrc);//先用base64解密
Base64.Decoder decoder = Base64.getDecoder();
byte[] encrypted1 = decoder.decode(sSrc);//先用base64解密
try {
byte[] original = cipher.doFinal(encrypted1);
String originalString = new String(original,"utf-8");
String originalString = new String(original, "utf-8");
return originalString;
} catch (Exception e) {
System.out.println(e.toString());
......
package com.wecloud.utils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.util.Base64;
/**
* @Author wenzhida
......@@ -17,7 +16,8 @@ public class Base64Util {
* @throws Exception
*/
public static byte[] decryBASE64(String key) throws Exception {
return (new BASE64Decoder()).decodeBuffer(key);
Base64.Decoder decoder = Base64.getDecoder();
return decoder.decode(key);
}
/***
......@@ -27,7 +27,8 @@ public class Base64Util {
* @throws Exception
*/
public static String encryptBASE64(byte[] key) throws Exception {
return (new BASE64Encoder()).encode(key);
Base64.Encoder encoder = Base64.getEncoder();
return encoder.encodeToString(key);
}
}
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