IturPablo
IturPablo

Reputation: 1611

Password encryption/decryption Spring security

I am encrypting the security in my web page with MD5 and Im using the following code.

public static String stringToMD5(String password)
    {

        MessageDigest messageDigest;

        try {
            messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(password.getBytes(),0, password.length());  
            String hashedPass = new BigInteger(1,messageDigest.digest()).toString(16);  
            if (hashedPass.length() < 32) {
               hashedPass = "0" + hashedPass; 
            }
            return hashedPass;
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
        return password;
    }

But because a custom way to log in I had to developed a custom AbstractAuthenticationProcessingFilter and now I have to decrypt that MD5.

So the question is how to decrypt the produced by that function.

Thanks in advance.

Upvotes: 1

Views: 4400

Answers (1)

Dmitry Ovsyanko
Dmitry Ovsyanko

Reputation: 1416

MD5 is a one-way algorithm. This is not a one-to-one mapping. There is no way to decrypt its output.

When working with stored MD5 encrypted passwords, you must authenticate users by encrypting their input and comparing the result to the stored encrypted password.

Upvotes: 2

Related Questions