mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-21 10:47:34 -05:00
Signed-off-by: Janos <86970079+janosdebugs@users.noreply.github.com> Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Signed-off-by: Roman Grinovski <roman.grinovski@gmail.com> Co-authored-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Co-authored-by: Roman Grinovski <roman.grinovski@gmail.com>
47 lines
1.8 KiB
Plaintext
47 lines
1.8 KiB
Plaintext
---
|
|
sidebar_label: base64decode
|
|
description: The base64decode function decodes a string containing a base64 sequence.
|
|
---
|
|
|
|
# `base64decode` Function
|
|
|
|
`base64decode` takes a string containing a Base64 character sequence and
|
|
returns the original string.
|
|
|
|
OpenTofu uses the "standard" Base64 alphabet as defined in
|
|
[RFC 4648 section 4](https://tools.ietf.org/html/rfc4648#section-4).
|
|
|
|
Strings in the OpenTofu language are sequences of unicode characters rather
|
|
than bytes, so this function will also interpret the resulting bytes as
|
|
UTF-8. If the bytes after Base64 decoding are _not_ valid UTF-8, this function
|
|
produces an error.
|
|
|
|
While we do not recommend manipulating large, raw binary data in the OpenTofu
|
|
language, Base64 encoding is the standard way to represent arbitrary byte
|
|
sequences, and so resource types that accept or return binary data will use
|
|
Base64 themselves, which avoids the need to encode or decode it directly in
|
|
most cases. Various other functions with names containing "base64" can generate
|
|
or manipulate Base64 data directly.
|
|
|
|
`base64decode` is, in effect, a shorthand for calling
|
|
[`textdecodebase64`](../../language/functions/textdecodebase64.mdx) with the encoding name set to
|
|
`UTF-8`.
|
|
|
|
## Examples
|
|
|
|
```
|
|
> base64decode("SGVsbG8gV29ybGQ=")
|
|
Hello World
|
|
```
|
|
|
|
## Related Functions
|
|
|
|
* [`base64encode`](../../language/functions/base64encode.mdx) performs the opposite operation,
|
|
encoding the UTF-8 bytes for a string as Base64.
|
|
* [`textdecodebase64`](../../language/functions/textdecodebase64.mdx) is a more general function that
|
|
supports character encodings other than UTF-8.
|
|
* [`base64gzip`](../../language/functions/base64gzip.mdx) applies gzip compression to a string
|
|
and returns the result with Base64 encoding.
|
|
* [`filebase64`](../../language/functions/filebase64.mdx) reads a file from the local filesystem
|
|
and returns its raw bytes with Base64 encoding.
|