PasswordBasedKeyProxy extends LunaKeyProxy implements KeyProxy { @Override public boolean matchesCanary(final EncryptionKeyCanary canary) { if (canary.getSalt() == null || canary.getSalt().length == 0) { return false; } final Key key = deriveKey(unmodifiableList(asList(ArrayUtils.toObject(canary.getSalt())))); final boolean result = super.matchesCanary(key, canary); if (result) { setKey(key); } return result; } 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 matchesCanary_whenCanaryDoesNotContainSalt_returnsFalse() { final EncryptionKeyCanary canary = new EncryptionKeyCanary(); canary.setSalt(null); assertFalse(subject.matchesCanary(canary)); }
@Test public void matchesCanary_whenCanaryHasEmptySalt_returnsFalse() { final EncryptionKeyCanary canary = new EncryptionKeyCanary(); canary.setSalt("".getBytes(UTF_8)); assertFalse(subject.matchesCanary(canary)); }