Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:56:26+00:00 2026-06-11T22:56:26+00:00

I am having an issue using the OOXML library when attempting to read encrypted

  • 0

I am having an issue using the OOXML library when attempting to read encrypted 2007 Excel documents. The password that I send to the DecryptToStream method is sending back a “Password not valid” message, but if I go directly into excel the password works fine. Below is the code I am using.

OleStorage ols = new OleStorage(d.fileLocation);
OfficeCrypto oc = new OfficeCrypto();
Stream test = oc.DecryptToStream(ols, "test123");

I have also tried using the POI Decryptor to attempt to read the encrypted 2007 excel, but I have had no luck with this as well. Below is code.

FileStream file = new FileStream(d.fileLocation, FileMode.Open, System.IO.FileAccess.Read);
NPOI.POIFS.FileSystem.POIFSFileSystem nfs;
nfs = new NPOI.POIFS.FileSystem.POIFSFileSystem(file);
Stream excelData;
try
{
    string password = "test123";
    EncryptionInfo info = new EncryptionInfo(nfs);
    Decryptor dc = Decryptor.GetInstance(info);

    if (!dc.VerifyPassword(password))
    {
        throw new NotImplementedException();
    }

    excelData = dc.GetDataStream(nfs);

}
catch (Exception ex)
{
    excelData = (Stream)file;
}

The VerifyPassword method always returns true no matter what I pass to it and it will still not read the document. I created the above code using http://poi.apache.org/encryption.html as a reference.

Any help would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:56:27+00:00Added an answer on June 11, 2026 at 10:56 pm

    As far as I know the current NPOI version 1.2.5 does not support Excel2007 files.
    Fortunately the NPOI 2.0 alpha version
    does support Excel2007 files but does not support encrypted Excel files.

    However, there is a project called OfficeOpenXmlCrypto
    which supports reading encrypted Excel files. The project is based on the NPOI version 1.2.1 and
    the ExcelPackage project to read Excel 2007 files.

    You can download the source of the OfficeOpenXmlCrypto project, replace
    the old NPOI library with the new NPOI 2.0 library and compile the project.

    Then, you can use a comibnation of the XSSFWorkbook and OfficeCryptoStream classes
    to read the content of an encrypted Excel file:

    using (OfficeCryptoStream ocs = OfficeCryptoStream.Open("c:\\temp\\secured.xlsx", "PA$$W0rd"))
    {
      NPOI.XSSF.UserModel.XSSFWorkbook w = new NPOI.XSSF.UserModel.XSSFWorkbook(ocs);
    
      NPOI.xssf.extractor.XSSFExcelExtractor ee = new NPOI.xssf.extractor.XSSFExcelExtractor(w);
    
      Console.Out.WriteLine(ee.Text);                    
    }
    

    As an alternative the EPPlus class library
    provides a class called ExcelPackage which provides support for
    encrypted Excel documents. This class also has a few properties (Workbook)
    to access the content of the Excel document.

    Here is a simple example reading the first cell of an encrypted Excel file:

    using (FileStream file = new FileStream("c:\\temp\\secure.xlsx", 
           FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite))
    {
      using (ExcelPackage ep = new ExcelPackage(file, "P@$$W0rd"))
      {
        Console.Out.WriteLine(ep.Workbook.Worksheets[1].Cells["A1"].Value);     
      }
    } 
    

    You can also use the OpenXml 2.0 SDK SpreadsheetDocument class in combination
    with the ExcelPackage class.

    Use the following code to read the content of the first cell (encrypted Excel document):

    using (FileStream file = new FileStream("c:\\temp\\secure.xlsx", 
           FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite))
    {
      using (ExcelPackage ep = new ExcelPackage(file, "P@$$W0rd"))
      {     
        using (SpreadsheetDocument sd = SpreadsheetDocument.Open(ep.Package))
        {
          WorkbookPart workbookPart = sd.WorkbookPart;
          WorksheetPart worksheetPart = workbookPart.WorksheetParts.Last();
          SheetData sheetData = worksheetPart.Worksheet.Elements<SheetData>().First();
    
          var row = sheetData.Elements<Row>().FirstOrDefault();
          var cell = row.Elements<Cell>().FirstOrDefault();
    
          Console.Out.WriteLine(cell.CellValue.InnerText);
        }
      }
    }
    

    The constructor of the ExcelPackage class throws an UnauthorizedAccessException if the password is invalid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue using the Moq library to mock an Enum within
I’m having an issue using ADFS2 to secure a back-end WCF service that is
Im having an issue using Java script to create a table that displays an
I'm having an issue using a new WPF app that is trying to display
Hello I am having an issue using the proj4js library. Here is my source:
I've been having an issue with using AudioRecord for Android. I've read as much
I am having a issue using Google's SDC (Secure Data Connector) with my Google
I'm having an issue using the Cookie class of the Servlet API 2.5 on
I'm having an issue using the qTip plugin with jQuery. I've created a js
I believe I am having a memory issue using numpy arrays. The following code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.