为什么ballerina不提供base64编码解码而只提供base64URL编码解码

Why ballerina doesn't provide a base64 encoding and decoding but only provide base64URL encoding and decoding

我注意到 ballerina 编码包没有 encodeBase64/decodeBase64 的方法,而是 encodeBase64URL/decodeBase64URL.

当我使用它和使用其他 base64 编码库时,结果不一样

base64编码[1]和base64URL编码[2]不同。 Ballerina 从语言本身提供 base64 encoding/decoding API。您可以将 ballerina/encoding 模块用于 base64 URL encoding/decoding.

import ballerina/io;

public function main() {
    string input = "Hello Ballerina!";
    byte[] inputArr = input.toBytes();
    string encodedString = inputArr.toBase64();
    io:println(encodedString);
}

更多示例请参考加密 BBE [3]。

[1] https://www.rfc-editor.org/rfc/rfc4648#section-4

[2] https://www.rfc-editor.org/rfc/rfc4648#section-5

[3] https://ballerina.io/v1-1/learn/by-example/crypto.html


[更新] base64 样本 encode/decode.

import ballerina/io;
import ballerina/lang.'array as arr;
import ballerina/lang.'string as str;

public function main() returns error? {
    string input = "Hello Ballerina!";
    byte[] inputArr = input.toBytes();
    string encodedString = inputArr.toBase64();
    io:println(encodedString);

    byte[] decoded = check arr:fromBase64(encodedString);
    string decodedString = check str:fromBytes(decoded);
    io:println(decodedString);
}