Re: Re: OT (sorry) base64 conversion in ruby

Rob Park
Fri, 06 May 2005 06:41:46 -0000

On 5/5/05, Florian Groß <florgro-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> What about this?
>
> irb(main):001:0>
Base64.encode64(Digest::SHA1.digest("foo")).chomp
> => "C+7Hteo/D9vJXQ3UfzxbwnXaijM="
> irb(main):018:0>
Digest::SHA1.hexdigest("foo").to_i(16).to_s(36)
> => "1e6gpc3ehk0mu2jqu8cg42g009s796b"
> irb(main):003:0> Digest::SHA1.hexdigest("foo")
> => "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"

Oh perfect, thanks. This is what I ended up doing:

Base64.encode64(Digest::MD5.digest("foo")).gsub(/=+\n?/, "")

(changed to md5 because it''s shorter, and added gsub because
there''s
really no reason for all the passwords to end with an equal sign and a
newline ;)

Thanks for your help!