Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Base64#decode64

decode64(str)

Returns a string containing the decoding of an RFC-2045-compliant Base64-encoded string str:

Example
s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
Base64.decode64(s) # => "This is line 1\nThis is line 2\n"

Non-Base64 characters in str are ignored; see Encoding Character Set above: these include newline characters and characters - and /:

Example
Base64.decode64("\x00\n-_") # => ""

Padding in str (even if incorrect) is ignored:

Example
Base64.decode64("MDEyMzQ1Njc")   # => "01234567"
Base64.decode64("MDEyMzQ1Njc=")  # => "01234567"
Base64.decode64("MDEyMzQ1Njc==") # => "01234567"
See also #encode64 #strict_decode64 also in 3.2 · 3.1 · 3.0