title: How to check if xlsx file is password protected or not using apache poi
body: <p>How to check if xlsx file is password protected or not. we can check for xls file as follows</p>
  
  <pre><code>FileInputStream fin = new FileInputStream(new File("C:/Book1.xls"));
              POIFSFileSystem poifs = new POIFSFileSystem(fin);
              EncryptionInfo info = new EncryptionInfo(poifs);
              Decryptor d = Decryptor.getInstance(info);
  
              try {
                  if (!d.verifyPassword(Decryptor.DEFAULT_PASSWORD)) {
                      throw new RuntimeException("Unable to process: document is encrypted");
                  }
  
                  InputStream dataStream = d.getDataStream(poifs);
                  HSSFWorkbook wb = new HSSFWorkbook(dataStream);
                  // parse dataStream
  
              } catch (GeneralSecurityException ex) {
                  throw new RuntimeException("Unable to process encrypted document", ex);
              }
  </code></pre>
  
  <p>But the above code works for only xls not for xlsx.</p>