title: How to encrypt/decrypt a file in Java?
body: <p>I am writing a Java application which can "encrypt" and consequently "decrypt" whatever binary file.</p>
  
  <p>I am just a beginner in the "cryptography" area so I would like to write a very simple application for the beginning.</p>
  
  <p>For reading the original file, I would probably use the <code>java.io.FileInputStream</code> class to get the "array of bytes" <code>byte originalBytes[]</code> of the file.</p>
  
  <p>Then I would probably use some very simple cipher, for example "<em>shift up every byte by 1</em>" and then I would get the "encrypted" bytes <code>byte encryptedBytes[]</code> and let's say that I would also set a "password" for it, for example "123456789".</p>
  
  <p>Next, when somebody wants to "decrypt" that file, he has to enter the password ("123456789") first and after that the file could be decrypted (thus "<em>shift down every byte by 1</em>") and consequently saved to the output file via <code>java.io.FileOutputStream</code>.</p>
  
  <p><br/>
  I am just wondering how to "store" the password information to the encrypted file so that the decrypting application knows if the entered password and the "real" password equals?</p>
  
  <p>Probably it would be silly to add the password (for example the ASCII ordinal numbers of the password letters) to the beginning of the file (before the encrypted data).</p>
  
  <p><br/>
  So my main question is <strong><em>how to store the password information to the encrypted file</em></strong>?</p>