bin.base64_to_hex
Available inall subroutines.
This function converts the Base64-encoded string s
into a hexadecimal sequence
of the same bytes. The hexadecimal sequence uses the symbols "0"
–"9"
to
represent the values 0 to 9, and "A"
–"F"
to represent the values 10 to 15.
bin.base64_to_hex
always uses two hexadecimal digits to represent a binary
value even if the numeric value fits within one hexadecimal digit (0-F).
For example, bin.base64_to_hex("AQ==")
is "01"
.
If the Base64-encoded string s
contains any null bytes, then
bin.base64_to_hex
does not terminate and does not return a truncated
hexadecimal sequence. For example, bin.base64_to_hex("AJ/CMw==")
is
"009FC233"
.
If the Base64-encoded string s
contains any non-alphabet characters, then
bin.base64_to_hex
terminates and returns a not set
value. For example,
bin.base64_to_hex("YWJ%jZA==")
is a not set
value.
If bin.base64_to_hex
is called with a not set
value or with an empty string
argument, then it returns the string ""
. For example, bin.base64_to_hex("")
is ""
.
To check if the return value is not an empty string or a not set
value, use
the std.strlen
function, which returns 0
in both cases.
if (std.strlen(bin.base64_to_hex(req.http.Base64-Input)) > 0) { // Do something if the hexadecimal representation of the Base64-encoded // input string is not an empty string or a not set value.}
Errors
If the Base64-encoded string s
is not valid Base64, then fastly.error
will be set to EINVAL
.
Examples
bin.base64_to_hex("AQIDBAUGBwgJ") # returns "010203040506070809"bin.base64_to_hex("AJ8AwgAzAA==") # returns "009F00C2003300"bin.base64_to_hex("-YWJjZA==") # returns a not set value and fastly.error is "EINVAL"bin.base64_to_hex("") # returns ""bin.base64_to_hex(not set string) # returns a not set valuebin.base64_to_hex("YWJjZA==") # returns "61626364"
User contributed notes
BETADo you see an error in this page? Do you have an interesting use case, example or edge case people should know about? Share your knowledge and help people who are reading this page! (Comments are moderated; for support, please contact Fastly support)