Package net.i2p.util
Class PasswordManager
java.lang.Object
net.i2p.util.PasswordManager
- Direct Known Subclasses:
RouterPasswordManager
public class PasswordManager extends Object
Manage both plaintext and salted/hashed password storage in
router.config.
There's no state here, so instantiate at will.
- Since:
- 0.9.4
-
Field Summary
Fields Modifier and Type Field Description protected static StringPROP_B64stored obfuscated as b64 of the UTF-8 bytesprotected static StringPROP_CRYPTstored as a Unix crypt stringprotected static StringPROP_MD5stored as the hex of the MD5 hash of the UTF-8 bytes.protected static StringPROP_PWstored as plain textprotected static StringPROP_SHASHstored as the b64 of the 16 byte salt + the 32 byte hash of the UTF-8 bytesprotected static intSALT_LENGTHprotected static intSHASH_LENGTH48 -
Constructor Summary
Constructors Constructor Description PasswordManager(I2PAppContext ctx) -
Method Summary
Modifier and Type Method Description booleancheck(String realm, String user, String pw)Checks both plaintext and hashbooleancheckB64(String realm, String user, String pw)booleancheckHash(String shash, String pw)Check pw against b64 salt+hash, as generated by createHash()booleancheckHash(String realm, String user, String pw)With random saltbooleancheckPlain(String realm, String user, String pw)StringcreateHash(String pw)Create a salt+hash, to be saved and verified later by verifyHash().Stringget(String realm, String user)Either plain or b64StringgetB64(String realm, String user)StringgetPlain(String realm, String user)static Stringmd5Hex(String fullpw)Straight MD5, no salt Will return the MD5 sum of the data, compatible with Jetty and RFC 2617.static Stringmd5Hex(String subrealm, String user, String pw)Straight MD5, no salt Will return the MD5 sum of "user:subrealm:pw", compatible with Jetty and RFC 2617.static byte[]md5Sum(byte[] data)Standard MD5 checksum
-
Field Details
-
SALT_LENGTH
protected static final int SALT_LENGTH- See Also:
- Constant Field Values
-
SHASH_LENGTH
protected static final int SHASH_LENGTH48- See Also:
- Constant Field Values
-
PROP_PW
stored as plain text- See Also:
- Constant Field Values
-
PROP_B64
stored obfuscated as b64 of the UTF-8 bytes- See Also:
- Constant Field Values
-
PROP_MD5
stored as the hex of the MD5 hash of the UTF-8 bytes. Compatible with Jetty.- See Also:
- Constant Field Values
-
PROP_CRYPT
stored as a Unix crypt string- See Also:
- Constant Field Values
-
PROP_SHASH
stored as the b64 of the 16 byte salt + the 32 byte hash of the UTF-8 bytes- See Also:
- Constant Field Values
-
-
Constructor Details
-
Method Details
-
check
Checks both plaintext and hash- Parameters:
realm- e.g. i2cp, routerconsole, etc.user- null or "" for no user, already trimmedpw- plain text, already trimmed- Returns:
- if pw verified
-
checkPlain
- Parameters:
realm- e.g. i2cp, routerconsole, etc.user- null or "" for no user, already trimmedpw- plain text, already trimmed- Returns:
- if pw verified
-
checkB64
- Parameters:
realm- e.g. i2cp, routerconsole, etc.user- null or "" for no user, already trimmedpw- plain text, already trimmed- Returns:
- if pw verified
-
checkHash
With random salt- Parameters:
realm- e.g. i2cp, routerconsole, etc.user- null or "" for no user, already trimmedpw- plain text, already trimmed- Returns:
- if pw verified
-
checkHash
Check pw against b64 salt+hash, as generated by createHash()- Parameters:
shash- b64 stringpw- plain text non-null, already trimmed- Returns:
- if pw verified
- Since:
- 0.9.24
-
createHash
Create a salt+hash, to be saved and verified later by verifyHash().- Parameters:
pw- plain text non-null, already trimmed- Returns:
- salted+hash b64 string
- Since:
- 0.9.24
-
get
Either plain or b64- Parameters:
realm- e.g. i2cp, routerconsole, etc.user- null or "" for no user, already trimmed- Returns:
- the pw or null
-
getPlain
- Parameters:
realm- e.g. i2cp, routerconsole, etc.user- null or "" for no user, already trimmed- Returns:
- the pw or null
-
getB64
- Parameters:
realm- e.g. i2cp, routerconsole, etc.user- null or "" for no user, already trimmed- Returns:
- the decoded pw or null
-
md5Hex
Straight MD5, no salt Will return the MD5 sum of "user:subrealm:pw", compatible with Jetty and RFC 2617. Updated in 0.9.26 to use UTF-8, as implied in RFC 7616/7617 See also http://stackoverflow.com/questions/7242316/what-encoding-should-i-use-for-http-basic-authentication http://stackoverflow.com/questions/702629/utf-8-characters-mangled-in-http-basic-auth-username- Parameters:
subrealm- to be used in creating the checksumuser- non-null, non-empty, already trimmedpw- non-null, plain text, already trimmed- Returns:
- lower-case hex with leading zeros, 32 chars, or null on error
-
md5Hex
Straight MD5, no salt Will return the MD5 sum of the data, compatible with Jetty and RFC 2617. Updated in 0.9.26 to use UTF-8, as implied in RFC 7616/7617 See also http://stackoverflow.com/questions/7242316/what-encoding-should-i-use-for-http-basic-authentication- Parameters:
fullpw- non-null, plain text, already trimmed- Returns:
- lower-case hex with leading zeros, 32 chars, or null on error
-
md5Sum
public static byte[] md5Sum(byte[] data)Standard MD5 checksum- Parameters:
data- non-null- Returns:
- 16 bytes, or null on error
-