PasswordBasedKeyProxy extends LunaKeyProxy implements KeyProxy { public List<Byte> generateSalt() { final byte[] salt = new byte[EncryptionConstants.SALT_SIZE]; secureRandom.nextBytes(salt); secureRandom.nextBytes(salt); return unmodifiableList(asList(ArrayUtils.toObject(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 generateSalt_returnsSaltOfAtLeastSizeOfHashFunctionOutput() { subject = new PasswordBasedKeyProxy("some password", 1, encryptionService); assertThat(subject.generateSalt().size(), greaterThanOrEqualTo(48)); }
@Test public void generateSalt_usesCorrectSecureRandom() { final InternalEncryptionService mockEncryptionService = mock(InternalEncryptionService.class); when(mockEncryptionService.getSecureRandom()).thenReturn(new SecureRandom()); subject = new PasswordBasedKeyProxy("some password", 1, mockEncryptionService); subject.generateSalt(); verify(mockEncryptionService).getSecureRandom(); }