pom:
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
package com.ruoyi.web;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) throws IOException {
String s="http://localhost:9080/wxpaytest/OAuthForWard.jsp";
//使用base64进行加密
sun.misc.BASE64Encoder base=new sun.misc.BASE64Encoder();
//指定utf-8编码
byte[] bytes = s.getBytes("utf-8");
//对数组进行加密
String encode = base.encode(bytes);
//加密后 得到:aHR0cDovL2xvY2FsaG9zdDo5MDgwL3d4cGF5dGVzdC9PQXV0aEZvcldhcmQuanNw
System.out.println(encode+"\n"+encode.length());
//进行解密
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
byte[] buffer = decoder.decodeBuffer(encode);
//指定utf-8解码
System.out.println(new String(buffer,"utf-8"));
}
}