Spring Security Encrypt MD5

前端 未结 3 1209
耶瑟儿~
耶瑟儿~ 2021-01-31 11:09

I have a java web application using spring framework and spring security for its login. In my database I have my passwords encrypted to MD5 before being saved. I added in my app

3条回答
  •  天涯浪人
    2021-01-31 11:45

    I realize this is a little late, but Spring has built-in classes that make this a lot easier.

    @Test
    public void testSpringEncoder() {
        PasswordEncoder encoder = new Md5PasswordEncoder();
        String hashedPass = encoder.encodePassword("koala", null);
    
        assertEquals("a564de63c2d0da68cf47586ee05984d7", hashedPass);
    }
    

    This is a unit test that I wrote using the built in Spring Security code, it is a lot smaller than the MessageDigest code and since you are using Spring Security already, you should have the classes in your classpath already.

提交回复
热议问题