Glassfish Security - jdbcRealm: How to configure login with SHA-256 digest

后端 未结 1 1110
离开以前
离开以前 2020-12-24 04:12

I use jdbcRealm for security in my glassfish v3.0.1 b22. It is set up so that it use the USER table inside my database for authentication by following this blog: http://blog

相关标签:
1条回答
  • 2020-12-24 04:17

    The jdbcRealm allows encoding values of hex or base64. You need to specify one of these in your realm configuration and in your code, convert the byte array into one of these formats:

    Base64:

    import com.sun.org.apache.xml.internal.security.utils.Base64;
    ...
    byte[] digest = md.digest();
    System.out.println(Base64.encode(digest));
    

    Hex:

    ...
    byte[] digest = md.digest();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < digest.length; i++) {
        String hex = Integer.toHexString(0xff & digest[i]);
        if (hex.length() == 1) sb.append('0');
        sb.append(hex);
    }
    System.out.println(sb.toString());
    

    btw, password field is type varchar(30)

    You'll need to increase the size of your password field. SHA-256 base64 and hex values are 45 and 64 characters in length, respectively.

    0 讨论(0)
提交回复
热议问题