BaseDecode

BaseDecode["string"]

decodes the Base64 data contained in a string and returns the result as a byte array.

BaseDecode["string","encoding"]

decodes using the string using the specified encoding.

Details

  • The result of BaseDecode["string"] is a ByteArray object.
  • Available encodings include:
  • "Base16"hexadecimal representation of byte values
    "Base64"default Base64 as described in the internet standard recommendation RFC 4648
    "Base85ASCII"Ascii85 or a85 encoding, with the "z shortcut"

Examples

open allclose all

Basic Examples  (2)

Decode a Base64-encoded string:

Decode a byte array using the Ascii85 encoding:

Scope  (2)

Encode the bytes 1 through 12:

The bytes can be recovered using BaseDecode:

Convert hexadecimal pairs to byte values:

View the individual bytes:

Properties & Relations  (8)

Characters outside the valid alphabet are automatically dropped:

The "Base16" format uses two characters for each byte value:

"Base64" encodes up to three bytes in each block of four characters:

Input must be properly padded to a multiple of four:

"Base85ASCII" can encode four bytes in a block of five characters:

Unlike other formats, padding is not required to yield a complete block:

The character "z" is special and denotes four consecutive zeros:

BaseEncode is the inverse of BaseDecode:

BaseEncode decodes a Base64-encoded string to binary data:

The import format "Base64" decodes a Base64 string and converts the resulting bytes to a string:

Achieve the same result with BaseDecode and ByteArrayToString:

BaseDecode converts the "Base64Encoding" format of Hash to its "ByteArray" format:

ByteArray uses Base64 encoding of its data in InputForm:

Possible Issues  (1)

Base64 inputs must be properly padded to the correct length:

Wolfram Research (2018), BaseDecode, Wolfram Language function, https://reference.wolfram.com/language/ref/BaseDecode.html (updated 2020).

Text

Wolfram Research (2018), BaseDecode, Wolfram Language function, https://reference.wolfram.com/language/ref/BaseDecode.html (updated 2020).

CMS

Wolfram Language. 2018. "BaseDecode." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/BaseDecode.html.

APA

Wolfram Language. (2018). BaseDecode. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BaseDecode.html

BibTeX

@misc{reference.wolfram_2024_basedecode, author="Wolfram Research", title="{BaseDecode}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/BaseDecode.html}", note=[Accessed: 22-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_basedecode, organization={Wolfram Research}, title={BaseDecode}, year={2020}, url={https://reference.wolfram.com/language/ref/BaseDecode.html}, note=[Accessed: 22-December-2024 ]}