### Question:
CipherEncryptionServiceImpl implements CipherEncryptionService { @Override public String encrypt( String clearPassword ) throws PasswordServiceException { try { Cipher encCipher = Cipher.getInstance( secretKey.getAlgorithm() ); encCipher.init( Cipher.ENCRYPT_MODE, secretKey, paramSpec ); byte[] toEncryptBytes = clearPassword.getBytes( UTF_8 ); byte[] encBytes = encCipher.doFinal( toEncryptBytes ); byte[] base64Bytes = Base64.encodeBase64( encBytes ); return new String( base64Bytes, UTF_8 ); } catch ( Exception ex ) { throw new PasswordServiceException( ex ); } } CipherEncryptionServiceImpl( String saltString, String algorithm, String encryptionKey, int iterations ); @Override String decrypt( String encryptedPassword ); @Override String encrypt( String clearPassword );  }### Answer:
@Test public void testCipherEncryptionWithDefaults() throws Exception { CipherEncryptionServiceImpl service = new CipherEncryptionServiceImpl( "_CyPh3r_", "PBEWithMD5AndDES", "P3ntah0C1ph3r", 19 ); String stringToEncrypt = "String To Encrypt"; String encryptedStringExpected = "R1pxG/vXQU8ezFM5VE644dqQxCKNP+Ap"; String encryptedStringActual = service.encrypt( stringToEncrypt ); Assert.assertEquals( encryptedStringExpected, encryptedStringActual ); }
@Test public void testSaltEffectOnEncryption() throws Exception { CipherEncryptionServiceImpl service = new CipherEncryptionServiceImpl( "DiffSalt", "PBEWithMD5AndDES", "P3ntah0C1ph3r", 19 ); String encryptedStringShouldNotBe = "R1pxG/vXQU8ezFM5VE644dqQxCKNP+Ap"; String stringToEncrypt = "String To Encrypt"; String encryptedStringActual = service.encrypt( stringToEncrypt ); Assert.assertNotSame( encryptedStringShouldNotBe, encryptedStringActual ); }
@Test public void testIterationsEffectOnEncryption() throws Exception { CipherEncryptionServiceImpl service = new CipherEncryptionServiceImpl( "_CyPh3r_", "PBEWithMD5AndDES", "P3ntah0C1ph3r", 25 ); String encryptedStringShouldNotBe = "R1pxG/vXQU8ezFM5VE644dqQxCKNP+Ap"; String stringToEncrypt = "String To Encrypt"; String encryptedStringActual = service.encrypt( stringToEncrypt ); Assert.assertNotSame( encryptedStringShouldNotBe, encryptedStringActual ); }