public class IdenticonUtil
extends java.lang.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.
コンストラクタ | 説明 |
---|---|
IdenticonUtil() |
修飾子とタイプ | メソッド | 説明 |
---|---|---|
static int |
getIdenticonCode(java.lang.String codeParam,
java.lang.String remoteAddr) |
Returns identicon code specified as an input parameter or derived from an
IP address.
|
static int |
getIdenticonCode(java.net.InetAddress inetAddr) |
Returns identicon code for given IP address.
|
static java.lang.String |
getIdenticonETag(int code,
int size,
int version) |
|
static int |
getIdenticonSize(java.lang.String param) |
|
static int |
getInetMask() |
Returns current IP address mask.
|
static java.lang.String |
getInetSalt() |
Returns current inetSalt value.
|
static void |
setInetMask(int inetMask) |
Sets current IP address mask.
|
static void |
setInetSalt(java.lang.String inetSalt) |
Sets current inetSalt value.
|
public static int getInetMask()
public static void setInetMask(int inetMask)
inetMask
- public static java.lang.String getInetSalt()
public static void setInetSalt(java.lang.String inetSalt)
inetSalt
- public static int getIdenticonCode(java.net.InetAddress inetAddr) throws java.lang.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 addressinetAddr
java.lang.Exception
public static int getIdenticonCode(java.lang.String codeParam, java.lang.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(java.lang.String param)
public static java.lang.String getIdenticonETag(int code, int size, int version)