@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
@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