zoukankan      html  css  js  c++  java
  • Base64编码

    Base64编码

    java.util.Base64

    package com.mozq.sb.jwt01.config;
    
    import java.nio.charset.Charset;
    import java.util.Base64;
    
    /**
     * @description: Base64编码
     */
    public class Base64Test {
        public static void main(String[] args) {
            //将字节数组编码成Base64字符串
            String src = "jie";
            String enc = Base64.getEncoder().encodeToString(src.getBytes());
            //不指定编码会使用默认的编码 Charset.defaultCharset().name()
            System.out.println(enc);
    
            //将Base64字符串解码成字节数组
            byte[] decode = Base64.getDecoder().decode(enc);
            String aSrc = new String(decode);
            System.out.println(aSrc);
    
            String defaultCharset = Charset.defaultCharset().name();
            System.out.println(defaultCharset);//UTF-8
        }
    }
    

    commons-codec

    <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.10</version>
    </dependency>
    
    package com.mozq.sb.jwt01.config;
    
    import org.apache.commons.codec.binary.Base64;
    
    import java.nio.charset.Charset;
    
    /**
     * @description: Base64编码
     */
    public class Base64Test_02 {
        public static void main(String[] args) {
            //将字节数组编码成Base64字符串
            String src = "jie//++--\";
            String enc = new Base64().encodeToString(src.getBytes());//amllLy8rKy0tXA==
    		//不指定编码会使用默认的编码 Charset.defaultCharset().name()
            System.out.println(enc);
            //将Base64字符串解码成字节数组
            byte[] decode = new Base64().decode(enc);
            String aSrc = new String(decode);
            System.out.println(aSrc);
    
            String defaultCharset = Charset.defaultCharset().name();
            System.out.println(defaultCharset);//UTF-8
        }
    }
    
  • 相关阅读:
    Djano restframework
    python测试一
    SQL分类,DDL,DML,DCL
    sql查询时,根据特定的条件给表的某一个字段赋值
    数据类型之Nullable
    web.config节点
    拼凑的宿主-host
    css的优先级
    jquery——write less,do more
    double类型计算
  • 原文地址:https://www.cnblogs.com/mozq/p/11980852.html
Copyright © 2011-2022 走看看