Java MessageDigest result does not stay constant

Posted by user344146 on Stack Overflow See other posts from Stack Overflow or by user344146
Published on 2010-05-18T14:56:09Z Indexed on 2010/05/18 15:10 UTC
Read the original article Hit count: 198

I've got this function for encrypting passwords in Java, but somehow when I call MessageDigest, it returns a different result every time even though I call it with the same password. I wonder if I am initializing it wrong somehow.

public String encrypt (String password) {
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    md.reset();     
    md.update(password.getBytes(Charset.forName("utf-8")),0,password.length());
    String res = md.digest().toString();
}

© Stack Overflow or respective owner

Related posts about java

Related posts about encryption