What is the main difference between (base64_encode) hashing and (sha1, md5, ...) ways? base64_encode is decode-able way, but it seems the others not. is it their main difference?
Yes, the main difference is that. Base64 is decodable, SHA1 and MD5 are not.
irb(main):001:0> source = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
=> "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
irb(main):002:0> require "base64"
=> true
irb(main):003:0> encoded = Base64.encode64(source)
=> "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBp\nc2NpbmcgZWxpdC4=\n"
irb(main):004:0> Base64.decode64(encoded)
=> "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
The other difference is the length of the hash. The length of a Base64 encoded string varies, because it contains the original data. However the length of SHA1 and MD5 hashes are fixed (20 byte for SHA1 and 16 byte for MD5).
irb(main):001:0> source = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
=> "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
irb(main):002:0> require "digest"
=> true
irb(main):003:0> Digest::SHA1.hexdigest(source)
=> "e7505beb754bed863e3885f73e3bb6866bdd7f8c"
irb(main):004:0> Digest::MD5.hexdigest(source)
=> "35899082e51edf667f14477ac000cbba"