forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p.zzz.sam' (head b328f0edb961263d7606ea964ecb3f7c319ca1cf)
to branch 'i2p.i2p' (head 7b4c0525be182722ef2cc7b564691f27d997da3b)
This commit is contained in:
@ -99,6 +99,18 @@ public class PasswordManager {
|
||||
String shash = _context.getProperty(pfx + PROP_SHASH);
|
||||
if (shash == null)
|
||||
return false;
|
||||
return checkHash(shash, pw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check pw against b64 salt+hash, as generated by createHash()
|
||||
*
|
||||
* @param shash b64 string
|
||||
* @param pw plain text non-null, already trimmed
|
||||
* @return if pw verified
|
||||
* @since 0.9.24
|
||||
*/
|
||||
public boolean checkHash(String shash, String pw) {
|
||||
byte[] shashBytes = Base64.decode(shash);
|
||||
if (shashBytes == null || shashBytes.length != SHASH_LENGTH)
|
||||
return false;
|
||||
@ -110,6 +122,23 @@ public class PasswordManager {
|
||||
return DataHelper.eq(hash, pwHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a salt+hash, to be saved and verified later by verifyHash().
|
||||
*
|
||||
* @param pw plain text non-null, already trimmed
|
||||
* @return salted+hash b64 string
|
||||
* @since 0.9.24
|
||||
*/
|
||||
public String createHash(String pw) {
|
||||
byte[] salt = new byte[SALT_LENGTH];
|
||||
_context.random().nextBytes(salt);
|
||||
byte[] pwHash = _context.keyGenerator().generateSessionKey(salt, DataHelper.getUTF8(pw)).getData();
|
||||
byte[] shashBytes = new byte[SHASH_LENGTH];
|
||||
System.arraycopy(salt, 0, shashBytes, 0, SALT_LENGTH);
|
||||
System.arraycopy(pwHash, 0, shashBytes, SALT_LENGTH, SessionKey.KEYSIZE_BYTES);
|
||||
return Base64.encode(shashBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Either plain or b64
|
||||
*
|
||||
|
Reference in New Issue
Block a user