/** * Encrypts given string with key generated from {@link #getPassword()} with given iteration count and return the masked * value (to be used as the variable). * * @param secretStr sensitive string to be protected by encryption * @param iterations iteration count * @return Encrypted value. */ protected String encrypt(String secretStr, int iterations) throws Exception { SecureRandom secureRandom = new SecureRandom(); byte[] salt = new byte[saltLengthBytes]; secureRandom.nextBytes(salt); byte[] encryptedVal = transform(Cipher.ENCRYPT_MODE, secretStr.getBytes(UTF8_CHARSET), salt, iterations); return new String(Base64.encode(salt), UTF8_CHARSET) + ":" + iterations + ":" + new String(Base64.encode(encryptedVal), UTF8_CHARSET); }
/** * Encrypts given string with key generated from {@link #getPassword()} with given iteration count and return the masked * value (to be used as the variable). * * @param secretStr sensitive string to be protected by encryption * @param iterations iteration count * @return Encrypted value. */ protected String encrypt(String secretStr, int iterations) throws Exception { SecureRandom secureRandom = new SecureRandom(); byte[] salt = new byte[saltLengthBytes]; secureRandom.nextBytes(salt); byte[] encryptedVal = transform(Cipher.ENCRYPT_MODE, secretStr.getBytes(UTF8_CHARSET), salt, iterations); return new String(Base64.encode(salt), UTF8_CHARSET) + ":" + iterations + ":" + new String(Base64.encode(encryptedVal), UTF8_CHARSET); }
@Override protected char[] getPassword() { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (passwordFile != null) { FileInputStream fis = new FileInputStream(passwordFile); try { baos.write(IOUtil.toByteArray(fis)); } finally { IOUtil.closeResource(fis); } } if (passwordUserProperties) { baos.write(System.getProperty("user.home").getBytes(UTF8_CHARSET)); baos.write(System.getProperty("user.name").getBytes(UTF8_CHARSET)); } if (passwordNetworkInterface != null) { try { NetworkInterface iface = NetworkInterface.getByName(passwordNetworkInterface); baos.write(iface.getHardwareAddress()); } catch (SocketException e) { throw rethrow(e); } } return new String(Base64.encode(baos.toByteArray()), UTF8_CHARSET).toCharArray(); } catch (Exception e) { throw rethrow(e); } }
@Override protected char[] getPassword() { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (passwordFile != null) { FileInputStream fis = new FileInputStream(passwordFile); try { baos.write(IOUtil.toByteArray(fis)); } finally { IOUtil.closeResource(fis); } } if (passwordUserProperties) { baos.write(System.getProperty("user.home").getBytes(UTF8_CHARSET)); baos.write(System.getProperty("user.name").getBytes(UTF8_CHARSET)); } if (passwordNetworkInterface != null) { try { NetworkInterface iface = NetworkInterface.getByName(passwordNetworkInterface); baos.write(iface.getHardwareAddress()); } catch (SocketException e) { throw rethrow(e); } } return new String(Base64.encode(baos.toByteArray()), UTF8_CHARSET).toCharArray(); } catch (Exception e) { throw rethrow(e); } }