I have this algorithm in Java to store passwords in database. I'd like to re-write my application in Ruby on Rails, so I need the same algorithm to compare hashed passwords. What's the Ruby equivalent of this algorithm?
public static String encrypt(String password) {
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA");
md.update(password.getBytes("UTF-8")); // step 3
byte raw[] = md.digest(); // step 4
String hash = (new BASE64Encoder()).encode(raw); // step 5
return hash; // step 6
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
Just for testing purpose, the "teste123" password generates this hash in my Java version: PQ87ndys7DDEAIxeAw5sE6R4y08=