java8 base64编码和解码
package com.oy; import java.nio.charset.StandardCharsets; import java.util.Base64; import org.junit.Test; public class demo04 { final Base64.Decoder decoder = Base64.getDecoder(); final Base64.Encoder encoder = Base64.getEncoder(); @Test public void testBase64() throws Exception { byte[] textByte = "admin:123".getBytes(StandardCharsets.UTF_8); String encodedText = encoder.encodeToString(textByte);//编码 System.out.println(encodedText);//YWRtaW46MTIz System.out.println(new String(decoder.decode(encodedText), "UTF-8"));//解码 } }
posted on 2019-09-03 09:22 wenbin_ouyang 阅读(1834) 评论(0) 编辑 收藏 举报