byte[]与字符串等价替换
package passwordProject;
import java.util.Base64;
public class sdf {
public static void main(String[] args) {
byte[] bytes = "hello world".getBytes();
String s = sdf.ByteToString(bytes);
System.out.println(s);
byte[] bytes1 = sdf.StringToByte(s);
System.out.println(new String(bytes1));
}
public static String ByteToString(byte[] bytes){
//Base64 Encoded
String encoded = Base64.getEncoder().encodeToString(bytes);
return encoded;
}
public static byte[] StringToByte(String str){
byte[] decoded = Base64.getDecoder().decode(str);
return decoded;
}
}