PasswordBasedKeyProxy extends LunaKeyProxy implements KeyProxy { public Key deriveKey() { if (salt == null) { salt = generateSalt(); } return deriveKey(salt); } PasswordBasedKeyProxy(final String password, final int numIterations, final InternalEncryptionService encryptionService); List<Byte> generateSalt(); Key deriveKey(); Key deriveKey(final List<Byte> salt); String getPassword(); void setPassword(final String password); @Override List<Byte> getSalt(); @Override boolean matchesCanary(final EncryptionKeyCanary canary); @Override Key getKey();  }
@Test public void deriveKey_returnstheExpectedKey() { final String knownRandomNumber = "7034522dc85138530e44b38d0569ca67"; final String knownGeneratedKey = "09cafa70264eaa47dcf0678dfd03aa73d24044df47b0381c17ebe0ed4e2f3d91"; final byte[] salt = Hex.decode(knownRandomNumber); final Key derivedKey = subject.deriveKey(Collections.unmodifiableList(asList(ArrayUtils.toObject(salt)))); final String hexOutput = Hex.toHexString(derivedKey.getEncoded()); assertThat(hexOutput, equalTo(knownGeneratedKey)); assertThat(derivedKey.getEncoded().length, equalTo(32)); }