Security Filters

Security Filters

Use security filters to encrypt and decrypt strings.

Note: Particularly for code that may be re-used across multiple sites, it is recommended to store secrets in a site setting where it can quickly and easily be updated.

base64_decode

Decodes a string in Base64 format.

base64_decode

{{ 'b25lIHR3byB0aHJlZQ==' | base64_decode }}
one two three

base64_encode

Encodes a string to Base64 format.

base64_encode

{{ 'one two three' | base64_decode }}
b25lIHR3byB0aHJlZQ==

base64_url_safe_decode

Decodes a string in URL-safe Base64 format.

base64_url_safe_decode

{{ 'b25lIHR3byB0aHJlZQ==' | base64_url_safe_decode }}
one two three

base64_url_safe_encode

Encodes a string to URL-safe Base64 format. To produce URL-safe Base64, this filter uses - and _ in place of + and /.

base64_url_safe_encode

{{ 'one two three' | base64_url_safe_encode }}
b25lIHR3byB0aHJlZQ==

decrypt_aes

Returns the unencrypted value of the input using a shared secret and optional salt. If no salt is provided, a default salt value is used.

decrypt_aes: String secret, String salt (optional)

{% var some_secret_string = entity.secret.value | encrypt_aes: site.shared_secret.value %} {% var shouldEqualOriginalValue = some_secret_string | decrypt_aes: site.shared_secret.value %}

encrypt_aes

Returns an encrypted value of the input using a shared secret and optional salt. If no salt is provided, a default salt value is used.

encrypt_aes: String secret, String salt (optional)

{% var some_secret_string = entity.secret.value | encrypt_aes: site.shared_secret.value %} {% var shouldEqualOriginalValue = some_secret_string | decrypt_aes: site.shared_secret.value %}

Examples

{% capture salt %}{{ entity.guid }}{{ entity.name.value }}{% endcapture %}
{% set salt = salt | url_encode %}
{% assign some_secret_string = entity.secret.value | encrypt_aes: site.shared_secret.value, salt %}
{% assign some_decoded_string = request.query_params.encrypted_data | decrypt_aes: site.shared_secret.value, salt %}