title: Java: How to write binary files?
body: <p>I have been doing web programming for several years now and since then I have not done any programming for desktop applications, and I have forgotten so many things. Please be patient if this is too simple.</p>
  
  <p>Now I have this situation:<br>
  I am trying to store some hashed words in a file. I think I should use binary files for this (please correct me if I am wrong). But I have no idea how should I write the words to the file. I tried many ways, but when I read back the file, and try to decrypt the words, I get <code>BadPaddingException</code>.</p>
  
  <p>Does anyone have any idea how to write the words to a file?</p>
  
  <p>P.S: I use this code for encrypting/decrypting the words (I got it from another StackOverflow thread, with a few modifications):</p>
  
  <pre><code>public static byte[] encrypt(String property) throws GeneralSecurityException, UnsupportedEncodingException {
          SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
          SecretKey key = keyFactory.generateSecret(new PBEKeySpec(password));
          Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
          pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(salt, 20));
          return pbeCipher.doFinal(property.getBytes("UTF-8"));
      }
  
      public static String decrypt(byte[] property) throws GeneralSecurityException, IOException {
          SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
          SecretKey key = keyFactory.generateSecret(new PBEKeySpec(password));
          Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
          pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(salt, 20));
          return new String(pbeCipher.doFinal(property));
      }
  </code></pre>