字符串base64编解码的多种语言完成

故事起源于逛v站的求职和招人贴,每次都是一长串字符,很疑惑,不知道是邮箱,照样微信号,照样钉钉,照样QQ。
《字符串base64编解码的多种语言完成》

觉得像是base64,又觉得不像,由于我之前只知道图片能转成base64,没想到字符串也能转,群里一问,还确实是base64。
《字符串base64编解码的多种语言完成》
因而风趣的事发生了,同学们纷纭用本身最善于的言语,把base64 字符串编解码完成了一遍…
《字符串base64编解码的多种语言完成》

我把小伙伴们用各种方式完成的要领整顿下,有linux shell,javascript,node,python,php,java,.net。

1.shell (author: Peng Zhao)

解码:echo "a2FsZUBvdWNodGVhbS5jb20=" | base64 -d
编码:echo "kale@ouchteam.com" | base64

2.javascript (author: Kai Gao)

var encodedData = window.btoa('kale@ouchteam.com'); // 编码
var decodedData = window.atob("a2FsZUBvdWNodGVhbS5jb20="); // 解码
console.log(encodedData,decodedData)

3.nodejs (author: Kai Gao)

//base64编码
var  b = new Buffer('kale@ouchteam.com');
var s = b.toString('base64')
console.log("邮箱编码:"+s)
//base64解码
var b = new Buffer('a2FsZUBvdWNodGVhbS5jb20=',"base64")
var s = b.toString();
console.log("邮箱解码:"+s)

4.python (author: Peng Zhao)

import base64
base64.b64encode("kale@ouchteam.com")
base64.b64decode("a2FsZUBvdWNodGVhbS5jb20=")

5.php (author: Chuang Shen)

<?php
$a = 'kale@ouchteam.com';
    $b = base64_encode($a);//编码
    echo $b;
    $c = base64_decode($b);//解码
    echo $c;  
?>

6.java (author: Chuang Shen)

String str = "kale@ouchteam.com";
        String encodeStr = new String(Base64.encode(str.getBytes()));
        System.out.println(encodeStr);
        String decodeStr = Base64.base64Decode(encodeStr);
        System.out.println(decodeStr);

7..net (author: Peng Li)

static void Main(string[] args)
        {
            Console.WriteLine("输入:");
            var str = Console.ReadLine();
            //加密
            byte[] EncryptionByte = Encoding.UTF8.GetBytes(str);
            var EncryptionStr = Convert.ToBase64String(EncryptionByte);

            Console.WriteLine("加密效果:" + EncryptionStr);

            //解密
            byte[] DecryptionByte = Convert.FromBase64String(EncryptionStr);
            var DecryptionStr = Encoding.UTF8.GetString(DecryptionByte);

            Console.WriteLine("解密效果:" + DecryptionStr);

        }

哈哈哈 我的小伙伴们都太可爱了!
That’s it ~

    原文作者:趁你还年轻
    原文地址: https://segmentfault.com/a/1190000012979438
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞