public class IdenticonUtil extends Object
Key method of interest is getIdenticonCode(java.net.InetAddress) which converts IP address
into identicon code.
IMPORTANT: inetSalt value must be set to
reasonably long random string prior to invoking this method.
| Constructor | Description |
|---|---|
IdenticonUtil() |
| Modifier and Type | Method | Description |
|---|---|---|
static int |
getIdenticonCode(String codeParam,
String remoteAddr) |
Returns identicon code specified as an input parameter or derived from an
IP address.
|
static int |
getIdenticonCode(InetAddress inetAddr) |
Returns identicon code for given IP address.
|
static String |
getIdenticonETag(int code,
int size,
int version) |
|
static int |
getIdenticonSize(String param) |
|
static int |
getInetMask() |
Returns current IP address mask.
|
static String |
getInetSalt() |
Returns current inetSalt value.
|
static void |
setInetMask(int inetMask) |
Sets current IP address mask.
|
static void |
setInetSalt(String inetSalt) |
Sets current inetSalt value.
|
public static int getInetMask()
public static void setInetMask(int inetMask)
inetMask - public static String getInetSalt()
public static void setInetSalt(String inetSalt)
inetSalt - public static int getIdenticonCode(InetAddress inetAddr) throws Exception
Current implementation uses first four bytes of SHA1(int(mask(ip))+salt) where mask(ip) uses inetMask to remove unwanted bits from IP address. Also, since salt is a string for convenience sake, int(mask(ip)) is converetd into a string and combined with inetSalt prior to hashing.
inetAddr - IP addressinetAddrExceptionpublic static int getIdenticonCode(String codeParam, String remoteAddr)
This method is a convenience method intended to be used by servlets like below:
int code = IdenticonUtil.getIdenticonCode(request.getParameter("code"), request
.getRemoteAddr());
codeParam - code parameter, if null remoteAddr parameter
will be used to determine the value.remoteAddr - HTTP requester's IP address. Optional if code was specified.public static int getIdenticonSize(String param)
public static String getIdenticonETag(int code, int size, int version)