title: AES Decryption Error
body: <p>Encryption is working optimally it seems the  text is appearing to be encrypted when looking at the file. Im stuck on the decryption process though and having errors:</p>
  
  <p>"Exception in thread "main" java.lang.NullPointerException
   at java.util.Arrays.copyOfRange(Arrays.java:3521)"</p>
  
  <p>Im calling the method using this:</p>
  
  <pre><code>char [] password;
  byte [] encrypted;
  decrypt(input, new File(outFile),encrypted,password);
  </code></pre>
  
  <p>// decrypt method</p>
  
  <pre><code>public void decrypt(File inputFile, File outputFile , byte [] encrypted, char [] password) throws Exception {
  
      byte[] iv = Arrays.copyOfRange(encrypted, 0, IV_SIZE_IN_BITS / 8);
       byte[] ciphertext = Arrays.copyOfRange(encrypted, iv.length, encrypted.length);
  
  
  
        Cipher cipher = initCipher(Cipher.DECRYPT_MODE, password,iv);
         FileOutputStream fos = null;
         CipherInputStream cis = null;
         FileInputStream fis = null;
         try {
             fis = new FileInputStream(inputFile);
             cis = new CipherInputStream(fis, cipher);
             fos = new FileOutputStream(outputFile);
             byte[] data = new byte[1024];
             int read = cis.read(data);
             while (read != -1) {
             fos.write(data, 0, read);
             read = cis.read(data);
             System.out.println(new String(data, "UTF-8").trim());
             }
         } finally {
             cis.close();
             fos.close();
             fis.close();
         }
  }
  </code></pre>
  
  <p>NEW---------</p>
  
  <pre><code> private static final String KEY_DERIVATION_FUNCTION = "PBKDF2WithHmacSHA256";
    private static final String ENCRYPTION_ALGORITHM    = "AES";
    private static final String TRANSFORMATION          = "AES/GCM/NoPadding";
    private static final String GENERATOR_ALGORITHM     = "SHA1PRNG";
  
    private static final int KEY_SIZE_IN_BITS = 128;
    private static final int  IV_SIZE_IN_BITS = 128;
    private static final int TAG_SIZE_IN_BITS = 128;
    private static final int ITERATION_COUNT  = 200_000;
  
  
  
  
  
  private static Cipher initCipher(int mode,char [] password, byte[] iv) {
  
      GCMParameterSpec gcmSpec = new GCMParameterSpec(TAG_SIZE_IN_BITS, iv);
  
      SecretKey key = deriveKey(password, iv);
      try {
  
        Cipher cipher = Cipher.getInstance(TRANSFORMATION);
        cipher.init(mode, key, gcmSpec);
        return cipher;
      }
  
      catch (
        NoSuchAlgorithmException |
        NoSuchPaddingException   |
        InvalidKeyException      |
        InvalidAlgorithmParameterException ex
      ) {
        throw new AssertionError(ex);
      }
   }
  </code></pre>