base64编码和解码_什么是Base64,以及如何编码和解码文本?

base64编码和解码

base64编码和解码

Base64 is an encoding and decoding algorithm. We need the encoding of some data in order to prevent storing and transmission problems. For example, If we try to transfer binary data it may create and affect some network devices because of its data structures. Base64 is generally used different applications like email and MIME, XML, JSON, URL, and HTTP, etc.

Base64是一种编码和解码算法。 我们需要对某些数据进行编码,以防止存储和传输问题。 例如,如果我们尝试传输二进制数据,由于其数据结构,它可能会创建并影响某些网络设备。 Base64通常用于不同的应用程序,例如电子邮件和MIME,XML,JSON,URL和HTTP等。

资料呈现 (Data Presentation)

Base64 uses alphabet, numbers and = for encoded data. For example, the following examples are valid Base64 encoded data

Base64将字母,数字和=用于编码数据。 例如,以下示例是有效的Base64编码数据

dGVzdA==
ZGVuZW1l

And following are not valid encoded data

以下是无效的编码数据

dG.?zdA==
ZG;,ZW1l

Base64不加密 (Base64 Is Not Encryption)

Base64 is just encoding format so it is not used to encrypt data to hide from third parties. Base64 encoded data can be easily reverted or decoded back to the text format. It can work two way without a security restriction of password.

Base64只是编码格式,因此它不用于加密数据以对第三方隐藏。 Base64编码的数据可以轻松地还原或解码回文本格式。 它可以两种方式工作,而没有密码的安全限制。

Linux Base64 (Linux Base64)

Now we will look some examples about to encrypt and decrypt Base64 in Linux bash environment.

现在,我们将看一些有关在Linux bash环境中加密和解密Base64的示例。

编码 (Encode)

We will encode file contents named data.txt with base64 command. We do not provide any option for this.

我们将使用base64命令对名为data.txt文件内容进行编码。 我们对此不提供任何选择。

$ base64 data.txt

解码 (Decode)

Decoding is very similar to encode we will just provide -d option to the base64 command like below. In this example, we will use a file named encoded.txt which contains base64 encoded data.

解码与编码非常相似,我们仅向base64命令提供-d选项,如下所示。 在此示例中,我们将使用一个名为encoded.txt的文件,其中包含base64编码的数据。

$ base64 -d encoded.txt

Javascript Base64 (Javascript Base64)

Javascript provides btoa and atob() functions which are a short form of binary to ascii and ascii to binary . We will just provide the text or data we want to convert to these functions like below.

Javascript提供了btoaatob()函数,它们是binary to ascii以及ascii to binary的缩写。 我们将仅提供要转换为以下功能的文本或数据,如下所示。

//Encode
atob("Test");

//Decode
btoa("VGVzdAo=")

PHP的Base64 (PHP Base64)

In PHP Programming language we can use base64_encode  and base64_decode  functions like below.

在PHP编程语言中,我们可以使用base64_encodebase64_decode函数,如下所示。

//Encoding 
base64_encode("Test");

//Decode
base64_decode("VGVzdAo=")
LEARN MORE  Linux uuencode Command Tutorial with Examples
了解更多Linux uuencode命令教程和示例

翻译自: https://www.poftut.com/what-is-base64-and-how-to-encode-and-decode-text/

base64编码和解码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值