Module basic module

module base64

base64 encoding and decoding module

base64Is a method of encoding binary data into an ASCII string so that it can be transmitted over a network. base64The module provides some support for Base64 encoding and decoding.

Using base64the module, you can encode a string into Base64 format and decode the Base64 format into a string. For example, to encode a string into Base64 format:

1 2 3 4 5 6
const { encode } = require('base64'); const str = 'hello, world'; const encodedStr = encode(str); console.log(encodedStr); // ==> "aGVsbG8sIHdvcmxk"

Decode a Base64-formatted string into a string:

1 2 3 4 5 6
const { decode } = require('base64'); const encodedStr = 'aGVsbG8sIHdvcmxk'; const str = decode(encodedStr); console.log(str); // ==> "hello, world"

Using Base64 encoding does not provide security when processing data that contains sensitive information. Because Base64 encoding can be easily broken, other more secure methods should be used to handle this data.

static function

encode

Encode data in base64 format

1 2
static String base64.encode(Buffer data, Boolean url = false);

Call parameters:

  • data:Buffer, the data to be encoded
  • url: Boolean, specifies whether to useurlsafe character encoding

Return results:

  • String, returns the encoded string

decode

Decode string into binary data in base64 mode

1
static Buffer base64.decode(String data);

Call parameters:

  • data: String, the string to be decoded

Return results:

  • Buffer, returns the decoded binary data