Skip to content

Latest commit

 

History

History
19 lines (16 loc) · 541 Bytes

encode-a-string-as-url-safe-base64.md

File metadata and controls

19 lines (16 loc) · 541 Bytes

Encode A String As URL-safe Base64

Ruby's standard lib comes with a Base64 module with a number of utilities for encoding and decoding data as Base64. One of the methods it provides is urlsafe_encode64.

> require 'base64'
true
> Base64.urlsafe_encode64('hello')
"aGVsbG8="
> Base64.urlsafe_encode64('1')
"MQ=="

You can pass it any string and it will create a URL-safe Base64 encoded representation of that string.