@Test public void testPasswordAffectsKey() throws Exception { PasswordBasedKdf kdf = new ScryptKdf(new SystemClock()); byte[] salt = getRandomBytes(32); Set<Bytes> keys = new HashSet<>(); for (int i = 0; i < 100; i++) { String password = getRandomString(16); SecretKey key = kdf.deriveKey(password, salt, 256); assertTrue(keys.add(new Bytes(key.getBytes()))); } }
@Override public SecretKey deriveKey(String password, byte[] salt, int cost) { long start = now(); byte[] passwordBytes = StringUtils.toUtf8(password); SecretKey k = new SecretKey(SCrypt.generate(passwordBytes, salt, cost, BLOCK_SIZE, PARALLELIZATION, SecretKey.LENGTH)); logDuration(LOG, "Deriving key from password", start); return k; }
ScryptKdf implements PasswordBasedKdf { @Override public SecretKey deriveKey(String password, byte[] salt, int cost) { long start = now(); byte[] passwordBytes = StringUtils.toUtf8(password); SecretKey k = new SecretKey(SCrypt.generate(passwordBytes, salt, cost, BLOCK_SIZE, PARALLELIZATION, SecretKey.LENGTH)); logDuration(LOG, "Deriving key from password", start); return k; } }
ScryptKdf implements PasswordBasedKdf { @Override public SecretKey deriveKey(String password, byte[] salt, int cost) { long start = now(); byte[] passwordBytes = StringUtils.toUtf8(password); SecretKey k = new SecretKey(SCrypt.generate(passwordBytes, salt, cost, BLOCK_SIZE, PARALLELIZATION, SecretKey.LENGTH)); logDuration(LOG, "Deriving key from password", start); return k; } @Inject  ScryptKdf(Clock clock); }
ScryptKdf implements PasswordBasedKdf { @Override public SecretKey deriveKey(String password, byte[] salt, int cost) { long start = now(); byte[] passwordBytes = StringUtils.toUtf8(password); SecretKey k = new SecretKey(SCrypt.generate(passwordBytes, salt, cost, BLOCK_SIZE, PARALLELIZATION, SecretKey.LENGTH)); logDuration(LOG, "Deriving key from password", start); return k; } @Inject  ScryptKdf(Clock clock); @Override int chooseCostParameter(); @Override SecretKey deriveKey(String password, byte[] salt, int cost); }
ScryptKdf implements PasswordBasedKdf { @Override public SecretKey deriveKey(String password, byte[] salt, int cost) { long start = now(); byte[] passwordBytes = StringUtils.toUtf8(password); SecretKey k = new SecretKey(SCrypt.generate(passwordBytes, salt, cost, BLOCK_SIZE, PARALLELIZATION, SecretKey.LENGTH)); logDuration(LOG, "Deriving key from password", start); return k; } @Inject  ScryptKdf(Clock clock); @Override int chooseCostParameter(); @Override SecretKey deriveKey(String password, byte[] salt, int cost);  }