Base64 修改

This commit is contained in:
limqhz
2020-01-31 01:47:03 +08:00
parent 604e07ad26
commit 7f9519acc8
2 changed files with 27 additions and 4 deletions

View File

@@ -0,0 +1,25 @@
package com.sv.service.api.util;
import org.apache.commons.codec.binary.Base64;
public class Base64Encoder {
/**
* @param bytes
* @return
*/
public static byte[] decode(final byte[] bytes) {
return Base64.decodeBase64(bytes);
}
/**
* 二进制数据编码为BASE64字符串
*
* @param bytes
* @return
* @throws Exception
*/
public static String encode(final byte[] bytes) {
return new String(Base64.encodeBase64(bytes));
}
}

View File

@@ -1,8 +1,6 @@
package com.sv.service.api.util;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
@@ -29,7 +27,7 @@ public class EncryptionUtil {
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); //生成加密解密需要的Key
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
byte[] bytes = cipher.doFinal(str.getBytes("UTF-8"));
result = new BASE64Encoder().encode(bytes);
result = Base64Encoder.encode(bytes);
} catch (Exception e) {
e.printStackTrace();
}
@@ -48,7 +46,7 @@ public class EncryptionUtil {
Cipher cipher = Cipher.getInstance(ALGORITHM, "BC");
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); //生成加密解密需要的Key
cipher.init(Cipher.DECRYPT_MODE, keySpec);
byte[] bytes = new BASE64Decoder().decodeBuffer(content);
byte[] bytes = Base64Encoder.decode(content.getBytes());
byte[] decoded = cipher.doFinal(bytes);
result = new String(decoded, "UTF-8");
} catch (Exception e) {