title: How to decrypt AES encrypted file with '-nosalt' param
body: <p>I'm new to encryption. This question is subquestion of my previous one. I have a file encrypted with OpenSSL util:</p>
  
  <pre><code>openssl aes-256-cbc -in fileIn -out fileOUT -p -k KEY
  </code></pre>
  
  <p>I'm using this code to decrypt it:</p>
  
  <pre><code>        byte[] encrypted = IOUtils.toByteArray(inputStream);
          Security.addProvider(new BouncyCastleProvider());
  
          String password = "abc";
  
          Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
  
          // Openssl puts SALTED__ then the 8 byte salt at the start of the
          // file. We simply copy it out.
          byte[] salt = new byte[8];
          System.arraycopy(encrypted, 8, salt, 0, 8);
          SecretKeyFactory fact = SecretKeyFactory.getInstance(
                  "PBEWITHMD5AND256BITAES-CBC-OPENSSL", "BC");
          c.init(Cipher.DECRYPT_MODE, fact.generateSecret(new PBEKeySpec(
                  password.toCharArray(), salt, 100)));
  
          // Decrypt the rest of the byte array (after stripping off the salt)
          byte[] data = c.doFinal(encrypted, 16, encrypted.length - 16);
  </code></pre>
  
  <p>And it works. But this is a test case. The real situation is that I have file encrypted with  these params:</p>
  
  <blockquote>
    <p>openssl aes-256-cbc -nosalt -in fileIn -out fileOUT -p -k KEY</p>
  </blockquote>
  
  <p>Notice that '-nosalt' param appeared. The issue is that PBEKeySpec requires not null and not empty <code>salt</code> and <code>iterationsCount</code> params. It also have constructor without these params but if I use it then I get an error:</p>
  
  <blockquote>
    <p>02-11 11:25:06.108: W/System.err(2155): java.security.InvalidKeyException: PBE requires PBE parameters to be set.</p>
  </blockquote>
  
  <p>The question is how to decrypt these files? How to handle '-nosalt' param correctly?</p>