Available in all subroutines.

Returns the Base64 encoding of the input string, as specified by RFC 4648 and is suitable for decoding by digest.base64_decode.

The alphabet used is:


The output string is padded to a multiple of four characters in length using the = character.

See digest.base64_decode for details on the structure of Base64 encoding. In particular, note that it is possible for two input strings to encode to the same Base64 string.


declare local var.base64_encoded STRING;
set var.base64_encoded = digest.base64("Καλώς ορίσατε");
# var.base64_encoded is now "zprOsc67z47PgiDOv8+Bzq/Pg86xz4TOtQ=="

Try it out

digest.base64 is used in the following code examples. Examples apply VCL to real-world use cases and can be deployed as they are, or adapted for your own service. See the full list of code examples for more inspiration.

Click RUN on a sample below to provision a Fastly service, execute the code on Fastly, and see how the function behaves.

Send HTTP Basic Auth in request to origin

Convert a password sent by the client in the querystring into a Authorization header to your origin server.

Cache GraphQL query response

GraphQL query requests are POSTs, but normally responses to POST can't be cached. Normalize the query and convert it to a querystring on a GET request to allow Fastly to cache these responses.