Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RoR - MD5 generation

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

like image 680
Mithun Sreedharan Avatar asked Nov 22 '10 07:11

Mithun Sreedharan


People also ask

How MD5 is generated?

The MD5 hashing algorithm uses a complex mathematical formula to create a hash. It converts data into blocks of specific sizes and manipulates that data a number of times. While this is happening, the algorithm adds a unique value into the calculation and converts the result into a small signature or hash.

How do you generate MD5 hash of a string?

An MD5 hash is created by taking a string of an any length and encoding it into a 128-bit fingerprint. Encoding the same string using the MD5 algorithm will always result in the same 128-bit hash output.

Why is MD5 no longer used?

Unfortunately, MD5 has been cryptographically broken and considered insecure. For this reason, it should not be used for anything. Instead, developers should switch to the Secure Hash Algorithm or a Symmetric Cryptographic Algorithm.

When did MD5 become obsolete?

In 2004, researchers revealed a number of weaknesses in regularly-used hash functions. Later in 2005, MD5 was declared "broken" by security expert Bruce Schneier.


1 Answers

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.

like image 169
joschi Avatar answered Sep 30 '22 12:09

joschi