JolokiaCipher { public String encrypt(final String pText) throws GeneralSecurityException { byte[] clearBytes = pText.getBytes(Charset.forName("UTF-8")); byte[] salt = getSalt(SALT_SIZE); Cipher cipher = createCipher(salt, Cipher.ENCRYPT_MODE); byte[] encryptedBytes = cipher.doFinal(clearBytes); int len = encryptedBytes.length; byte padLen = (byte) (CHUNK_SIZE - (SALT_SIZE + len + 1) % CHUNK_SIZE); int totalLen = SALT_SIZE + len + padLen + 1; byte[] allEncryptedBytes = getSalt(totalLen); System.arraycopy(salt, 0, allEncryptedBytes, 0, SALT_SIZE); allEncryptedBytes[SALT_SIZE] = padLen; System.arraycopy(encryptedBytes, 0, allEncryptedBytes, SALT_SIZE + 1, len); return Base64Util.encode(allEncryptedBytes); } JolokiaCipher();  JolokiaCipher(KeyHolder pKeyHolder); String encrypt(final String pText); String decrypt(final String pEncryptedText); static final String JOLOKIA_CYPHER_PASSWORD; }
@Test public void testSalt() throws Exception { String enc = cipher.encrypt(clearText); assertNotNull(enc); String enc2 = cipher.encrypt(clearText); assertNotNull(enc2); assertNotEquals(enc,enc2); }