RoR - MD5 generation

RubyHashMd5Digest

Ruby Problem Overview


How can I encrypt a string with MD5 in Rails 3.0 ? pass = MD5.hexdigest(pass) in a model yields uninitialized constant MyModel::MD5

Ruby Solutions


Solution 1 - Ruby

You can use Digest::MD5 from the Ruby standard library for this.

irb(main):001:0> require 'digest/md5'
=> true
irb(main):002:0> Digest::MD5.hexdigest('foobar')
=> "3858f62230ac3c915f300c664312c63f"

And one more thing: MD5 is a hash algorithm. You don't "encrypt" anything with a hash algorithm.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMithun SreedharanView Question on Stackoverflow
Solution 1 - RubyjoschiView Answer on Stackoverflow