编程语言
首页 > 编程语言> > Base64加密算法

Base64加密算法

作者:互联网

java的Base64加密与解密

import java.util.Base64;

public class Hello {
    public static void main(String[] args){
        String name = "哈喽啊";
        //base64,加密
        Base64.Encoder encoder = Base64.getEncoder();
        String res = encoder.encodeToString(name.getBytes());
        System.out.println(res); // 5ZOI5Za95ZWK

        // base64,解密
        Base64.Decoder decoder = Base64.getDecoder();
        byte[] origin = decoder.decode(res);
        String data = new String(origin);
        System.out.println(data);
    }
}

python的Base64加密与解密:

import base64

name = "哈喽啊"
#加密
res = base64.b64encode(name.encode('utf-8'))
print(res)

#将res以utf-8方式解密成字节的形式
data = base64.b64decode(res.decode('utf-8'))
#再将data以utf-8的方式解码成字符串的数据
origin = data.decode('utf-8')
print(origin)

标签:base64,utf,String,res,Base64,data,加密算法
来源: https://www.cnblogs.com/zhiqianggege/p/16211882.html