Skip to content

Latest commit

 

History

History
54 lines (36 loc) · 1.12 KB

File metadata and controls

54 lines (36 loc) · 1.12 KB
title crypt.base64encode

Encodes data into a Base64 string.

crypt.base64encode(data: string): string

Base64 turns any data - even bytes that aren't normal text - into plain text characters. That lets it go through JSON, a remote, or a file without breaking. The result is about a third bigger than the input.

Most commonly used to make a binary payload safe to send over request or store with writefile.

Parameters

Parameter Type Description
data string The bytes to encode.

Returns

string - the Base64-encoded text.

Aliases

  • base64.encode
  • base64_encode
  • base64encode
  • crypt.base64.encode
  • crypt.base64_encode

Example

Encode a value with Base64, then cache it to disk with writefile.

local base64encode = crypt.base64encode("Hello, world!")
local blob = crypt.base64encode("Hello, world!")
print(blob) --> "SGVsbG8sIHdvcmxkIQ=="

writefile("config.cache", blob)
Useful for encoding binary payloads before saving or transmission.