Ruby 2.0.0 リファレンスマニュアル > ライブラリ一覧 > base64ライブラリ > Base64モジュール
クラスの継承リスト: Base64
Base64 エンコード / デコードするためのメソッドを定義したモジュールです。
decode64(str) -> String[permalink][rdoc]与えられた文字列を Base64 デコードしたデータを返します。
このメソッドは [RFC2045] に対応しています。
require 'base64'
str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' +
'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
puts Base64.decode64(str)
# This is line one
# This is line two
# This is line three
# And so on...
encode64(bin) -> String[permalink][rdoc]与えられたデータを Base64 エンコードした文字列を返します。
このメソッドは [RFC2045] に対応しています。 エンコード後の文字で 60 文字ごとに改行を追加します。
require 'base64'
Base64.encode64("Now is the time for all good coders\nto learn Ruby")
# => Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
# UnVieQ==
strict_decode64(str) -> String[permalink][rdoc]与えられた文字列を Base64 デコードしたデータを返します。
このメソッドは [RFC4648] に対応しています。
strict_encode64(bin) -> String[permalink][rdoc]与えられたデータを Base64 エンコードした文字列を返します。
このメソッドは [RFC4648] に対応しています。 改行コードを追加することはありません。
urlsafe_decode64(str) -> String[permalink][rdoc]与えられた文字列を Base64 デコードしたデータを返します。
このメソッドは [RFC4648] の "Base 64 Encoding with URL and Filename Safe Alphabet" に対応しています。 "+" を "-" に "/" を "_" に置き換えます。
urlsafe_encode64(bin) -> String[permalink][rdoc]与えられたデータを Base64 エンコードした文字列を返します。
このメソッドは [RFC4648] の "Base 64 Encoding with URL and Filename Safe Alphabet" に対応しています。 "+" を "-" に "/" を "_" に置き換えます。