Spring Security Encrypt MD5

前端 未结 3 1196
耶瑟儿~
耶瑟儿~ 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:39

    How are you creating your MD5 hashes? Something like the following works well in Java:

    MessageDigest messageDigest = MessageDigest.getInstance("MD5");  
    messageDigest.update(user.getPassword().getBytes(),0, user.getPassword().length());  
    String hashedPass = new BigInteger(1,messageDigest.digest()).toString(16);  
    if (hashedPass.length() < 32) {
       hashedPass = "0" + hashedPass; 
    }
    

    When you encode "koala" do you get "a564de63c2d0da68cf47586ee05984d7"?

提交回复
热议问题