package com.example.demo.study;
import java.nio.charset.StandardCharsets;
import java.time.Clock;
import java.util.Base64;
public class Base64Study {
public static void main(String[] args) {
String content = "zhuzhenqi";
byte [] b = content.getBytes(StandardCharsets.UTF_8);
//加密
String s = Base64.getEncoder().encodeToString(b);
System.out.println(s);
//解密
byte[] decode = Base64.getDecoder().decode(s);
String s1 = new String(decode,StandardCharsets.UTF_8);
System.out.println(s1);
//当前时间
System.out.println(Clock.systemUTC().millis());
//当前时间
System.out.println(System.currentTimeMillis());
}
}
打印结果:
emh1emhlbnFp
zhuzhenqi
1546917893445
1546917893445