Base64编码和解码字符串

2024-10-09 10:54:54 浏览数 (1)

Base64编码和解码字符串

代码语言:javascript复制
package com.example.core.mydemo.cpic;

import org.apache.commons.codec.binary.Base64;

/**
 * strEncode=aGVsbG8gd29ybGQ=
 * strDecode=hello world
 */
public class BizRequestBase64Test {
    private static final String CHAR_SET_UTF_8 = "UTF-8";

    public static void main(String[] args) throws Exception{
        String str = "hello world";
        String strEncode = new Base64().encodeToString(str.getBytes(CHAR_SET_UTF_8));
        System.out.println("strEncode="   strEncode);

        byte[] biz_request = new Base64().decode(strEncode.getBytes(CHAR_SET_UTF_8));
        System.out.println("strDecode="   new String(biz_request));

    }
}

0 人点赞