赞
踩
加密返回如下:
ZHNhZmFzZnNhZmFzZnNhZmFzZmFzZ2FzZg==
解密返回如下:
dsafasfsafasfsafasfasgasf
package test;
import java.util.Base64;
/**
* zt
* 2020/9/14
* 17:40
*/
public class MyTest {
//加密
public static String encode(String str){
/*String encode = Base64.getEncoder().encodeToString(str.getBytes());
System.out.println(str + "\t编码后的字符串为:" + encode);
return str;*/
return new String(Base64.getEncoder().encode(str.getBytes()));
}
//解密
public static String decode(String str){
/* String decode = new String(Base64.getDecoder().decode(str));
System.out.println(str + "\t字符串解码后为:" + decode);
return decode;*/
return new String(Base64.getDecoder().decode(str));
}
public static void main(String[] args) {
String str = "asadasdas";
//加密
/*String encode = Base64.getEncoder().encodeToString(str.getBytes());
System.out.println(str + "\t编码后的字符串为:" + encode);
//解密
String decode = new String(Base64.getDecoder().decode(encode));
System.out.println(encode + "\t字符串解码后为:" + decode);*/
String encode = encode(str);
System.out.println(encode);
String decode = decode(encode);
System.out.println(decode);
}
}
运行结果1
运行结果2
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。