Package com.docuverse.identicon
Class IdenticonUtil
java.lang.Object
com.docuverse.identicon.IdenticonUtil
public class IdenticonUtil extends Object
Utility methods useful for implementing identicon functionality. Methods are
class methods for convenience.
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.
- Author:
- don
-
Constructor Summary
Constructors Constructor Description IdenticonUtil()
-
Method Summary
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.
-
Constructor Details
-
IdenticonUtil
public IdenticonUtil()
-
-
Method Details
-
getInetMask
public static int getInetMask()Returns current IP address mask. Default is 0xffffffff.- Returns:
- current IP address mask
-
setInetMask
public static void setInetMask(int inetMask)Sets current IP address mask. Default is 0xffffffff.- Parameters:
inetMask
-
-
getInetSalt
Returns current inetSalt value.- Returns:
- the value
-
setInetSalt
Sets current inetSalt value.- Parameters:
inetSalt
-
-
getIdenticonCode
Returns identicon code for given IP address.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.
- Parameters:
inetAddr
- IP address- Returns:
- identicon code for
inetAddr
- Throws:
Exception
-
getIdenticonCode
Returns identicon code specified as an input parameter or derived from an IP address.This method is a convenience method intended to be used by servlets like below:
int code = IdenticonUtil.getIdenticonCode(request.getParameter("code"), request .getRemoteAddr());
- Parameters:
codeParam
- code parameter, ifnull
remoteAddr parameter will be used to determine the value.remoteAddr
- HTTP requester's IP address. Optional if code was specified.- Returns:
- the code
-
getIdenticonSize
-
getIdenticonETag
-