@Override public String encrypt(String salt, String password, String textToEncrypt) throws JasDBSecurityException { String standardPass = getStandardizedPassword(password); PBEKeySpec keySpec = new PBEKeySpec(standardPass.toCharArray(), Hex.decode(salt), 1024, 128); try { byte[] iv = new byte[IV_SIZE]; secureRandom.nextBytes(iv); SecretKey secretKey = new SecretKeySpec(SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(keySpec).getEncoded(), "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(iv)); byte[] encrypted = cipher.doFinal(textToEncrypt.getBytes(UTF8)); return new String(Hex.encode(appendArrays(iv, encrypted))); } catch (InvalidKeySpecException e) { throw new JasDBSecurityException("Unable to encrypt", e); } catch (NoSuchAlgorithmException e) { throw new JasDBSecurityException("Unable to encrypt", e); } catch (NoSuchPaddingException e) { throw new JasDBSecurityException("Unable to encrypt", e); } catch (InvalidAlgorithmParameterException e) { throw new JasDBSecurityException("Unable to encrypt", e); } catch (InvalidKeyException e) { throw new JasDBSecurityException("Unable to encrypt", e); } catch (BadPaddingException e) { throw new JasDBSecurityException("Unable to encrypt", e); } catch (IllegalBlockSizeException e) { throw new JasDBSecurityException("Unable to encrypt", e); } }