Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How can protected workbook excel file with npoi #1312

Open
2 of 5 tasks
mjjalala opened this issue Apr 9, 2024 · 3 comments
Open
2 of 5 tasks

How can protected workbook excel file with npoi #1312

mjjalala opened this issue Apr 9, 2024 · 3 comments

Comments

@mjjalala
Copy link

mjjalala commented Apr 9, 2024

@tonyqus
I have code that uses the NPOI library to export files to Excel. I want to use Protected Workbook to protect the file after exporting it. I see there is a problem when using EncryptionInfo. The error is "Object reference null"

Is there any example of password protecting workbook? Not the worksheet but whole workbook.

My code is:
' ******** Code I am trying to get to work that encrypts and password protects the Excel file
'sheet1.ProtectSheet("password") ' to be replaced with dynamic password - this is a hardcoded placeholder
'Dim fs As New NPOIFSFileSystem
'Dim cm As ChainingMode = ChainingMode.cbc
'Dim info As New EncryptionInfo(fs, EncryptionMode.Agile) ' EncryptionInfo(EncryptionMode.Agile, CipherAlgorithm.aes192, HashAlgorithm.sha384, -1, -1, cm)
'Dim enc As Encryptor = info.Encryptor
'enc.ConfirmPassword("password") ' to be replaced with dynamic password - this is a hardcoded placeholder
'Using encryptedStream As Stream = enc.GetDataStream(fs)
'Using memoryStream As MemoryStream = New MemoryStream()
'workbook.Write(memoryStream)
'Dim encryptedBytes As Byte() = memoryStream.ToArray()
'encryptedStream.Write(encryptedBytes, 0, encryptedBytes.Length)
'Using fileStream As FileStream = New FileStream("encrypted.xlsx", FileMode.Create)
'encryptedStream.CopyTo(fileStream)
'End Using
'End Using
'End Using
' ******** Code I am trying to get to work that encrypts and password protects the Excel file

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER
@mjjalala mjjalala added the bug label Apr 9, 2024
@mjjalala mjjalala changed the title issue when using EncryptionInfo in NPOI.POIFS.Crypt How can protected workbook excel file with npoi Apr 14, 2024
@tonyqus tonyqus added this to the NPOI vNext milestone Apr 15, 2024
@tonyqus
Copy link
Member

tonyqus commented Apr 15, 2024

It's not supported so far. NPOI can only open encrypted xlsx since 2.6.0.

Check PR #883 for detail

@mjjalala
Copy link
Author

@tonyqus Do you have an estimated date to have this issue solved?

@tonyqus
Copy link
Member

tonyqus commented Apr 24, 2024

There is no plan for this feature

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants