Java语言提供了一个非常好的BASE64算法的实现,即Apache Commons Codec工具包。其MAVEN配置如下,
</dependency>
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec --><dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
- String str = "Hello World";
-
- try{
- byte[] encodeBase64 = Base64.encodeBase64(str.getBytes("UTF-8"));
- System.out.println("Result: " + new String(encodeBase64));
- } catch(UnsupportedEncodingException e){
- e.printStackTrace();
- }