frombase64()
Decodes a Base64-encoded string and returns it as binary.
Syntax
frombase64(BASE64_STR)
Parameters
BASE64_STR- A Base64-encoded string or expression.
Description
The frombase64() function decodes a Base64-encoded string and returns it as binary (byte[]). If the argument is null, returns null. If Base64 decoding fails, also returns null.
The returned binary value can be used with functions that accept binary as an argument, such as decode(), tohex(), and tobase64().
Error codes
| Error code | Description |
|---|---|
| 90680 | No argument was provided. |
Usage examples
-
Decoding a Base64 string to binary
json "{'val': 'aGVsbG8sIHdvcmxkIQ=='}" | eval result = tohex(frombase64(val)) | # result: "68656c6c6f2c20776f726c6421" -
Decoding and converting to a string
json "{'val': 'aGVsbG8sIHdvcmxkIQ=='}" | eval result = decode(frombase64(val)) | # result: "hello, world!" -
NULL input
json "{'val': null}" | eval result = frombase64(val) | # result: null
Compatibility
The frombase64() function has been available since before Sonar 4.0.