Decodes a character string, raw vector or other object from base64 encoding.
Arguments
- x
an object.
- convert
logical
TRUEto convert back to a character string,FALSEto convert back to a raw vector orNAto decode and then unserialize back to the original object.- url
logical
TRUEto use the URL- and filename-safe base64url alphabet without padding, orFALSE(the default) for standard base64.
Details
The value of convert should be set to TRUE, FALSE or NA to be the
reverse of the 3 encoding operations (for strings, raw vectors and arbitrary
objects), in order to return the original object.
Set url = TRUE to decode the URL- and filename-safe variant (RFC 4648
section 5), which expects the - and _ alphabet without padding; inputs
containing +, / or = are then rejected. The value of url must match
the variant used to encode.
References
This implementation is based that by 'The Mbed TLS Contributors' under the 'Mbed TLS' Trusted Firmware Project at https://www.trustedfirmware.org/projects/mbed-tls.
Examples
base64dec(base64enc("secret base"))
#> [1] "secret base"
base64dec(base64enc(as.raw(c(1L, 2L, 4L))), convert = FALSE)
#> [1] 01 02 04
base64dec(base64enc(data.frame()), convert = NA)
#> data frame with 0 columns and 0 rows
base64dec(base64enc("secret base", url = TRUE), url = TRUE)
#> [1] "secret base"