title: Get the same input File format after Encryt --> base64 Encode-->Encrypted file -->base64decode-->Decrypt--->decrypted file
body: <p>I'm converting a text file to enc file in the following way:</p>
  
  <ol>
  <li>Read through file input stream.  </li>
  <li>Encrypt  </li>
  <li>Encode using base 64.  </li>
  <li>Use File output stream to write to .enc file.  </li>
  <li>Read .enc file through file input stream  </li>
  <li>Decode using base 64.  </li>
  <li>d e crypt </li>
  <li>Use File output stream to write to text file.  </li>
  </ol>
  
  <p>I'm not able to get the same output format as the input file. The output is the same.</p>
  
  <pre class="lang-java prettyprint-override"><code>//Encrypt
  inFile = new FileInputStream(path + "/" + fileName);
  outFile = new FileOutputStream(encfileName);
  byte[] input = new byte[64];
              int bytesRead;
              while ((bytesRead = inFile.read(input)) != -1) {
                  byte[] output = cipher.update(input, 0, bytesRead);
                  if (output != null)
  
                      outFile.write(Base64.getEncoder().encode(output));
              }
  
              byte[] output = cipher.doFinal();
              if (output != null)
                  outFile.write(Base64.getEncoder().encode(output));
  
  //Decrypt
  fis = new FileInputStream(path + "/" + encryptedFile);
              fos = new FileOutputStream(decryptedFile);
              byte[] in = new byte[64];
              int read;
              while ((read = decoder.wrap(fis).read(in)) != -1) {
                  byte[] output = cipher.update(in, 0, read);
                  if (output != null)
                      fos.write(output);
              }
  
              byte[] output = cipher.doFinal();
              if (output != null)
                  fos.write(output);
  
  
  
  </code></pre>
  
  <p>Any suggestions?</p>