POIFSFileSystem filesystem = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(EncryptionMode.Agile);
Encryptor e = Encryptor.GetInstance(info);
e.ConfirmPassword(password);
var os = e.GetDataStream(filesystem);
IWorkbook wb = new XSSFWorkbook(stream);
wb.Write(os);
MemoryStream result = new MemoryStream();
if (os.Position > 0) os.Seek(0, SeekOrigin.Begin);
await os.CopyToAsync(result);
if (result.Position > 0) result.Seek(0, SeekOrigin.Begin);
return result ;
line var os = e.GetDataStream(filesystem); returns
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=NPOI.Core
StackTrace:
at NPOI.POIFS.Crypt.CryptoFunctions.GetCipher(IKey key, CipherAlgorithm cipherAlgorithm, ChainingMode chain, Byte[] vec, Int32 cipherMode, String padding)
at NPOI.POIFS.Crypt.Agile.AgileDecryptor.InitCipherForBlock(Cipher existing, Int32 block, Boolean lastChunk, IEncryptionInfoBuilder builder, ISecretKey skey, Int32 encryptionMode)
at NPOI.POIFS.Crypt.Agile.AgileEncryptor.AgileCipherOutputStream.InitCipherForBlock(Cipher existing, Int32 block, Boolean lastChunk)
at NPOI.POIFS.Crypt.ChunkedCipherOutputStream..ctor(DirectoryNode dir, Int32 chunkSize, IEncryptionInfoBuilder builder, Encryptor encryptor)
at NPOI.POIFS.Crypt.Agile.AgileEncryptor.AgileCipherOutputStream..ctor(DirectoryNode dir, IEncryptionInfoBuilder builder, ISecretKey skey, AgileEncryptor encryptor)
at NPOI.POIFS.Crypt.Agile.AgileEncryptor.GetDataStream(DirectoryNode dir)
at NPOI.POIFS.Crypt.Encryptor.GetDataStream(POIFSFileSystem fs)
Issue Description
Trying to prepare encrypted stream to be saved to file.
NPOI Version
2.6.2
File Type
any file even empty
Reproduce Steps
line var os = e.GetDataStream(filesystem); returns System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=NPOI.Core StackTrace: at NPOI.POIFS.Crypt.CryptoFunctions.GetCipher(IKey key, CipherAlgorithm cipherAlgorithm, ChainingMode chain, Byte[] vec, Int32 cipherMode, String padding) at NPOI.POIFS.Crypt.Agile.AgileDecryptor.InitCipherForBlock(Cipher existing, Int32 block, Boolean lastChunk, IEncryptionInfoBuilder builder, ISecretKey skey, Int32 encryptionMode) at NPOI.POIFS.Crypt.Agile.AgileEncryptor.AgileCipherOutputStream.InitCipherForBlock(Cipher existing, Int32 block, Boolean lastChunk) at NPOI.POIFS.Crypt.ChunkedCipherOutputStream..ctor(DirectoryNode dir, Int32 chunkSize, IEncryptionInfoBuilder builder, Encryptor encryptor) at NPOI.POIFS.Crypt.Agile.AgileEncryptor.AgileCipherOutputStream..ctor(DirectoryNode dir, IEncryptionInfoBuilder builder, ISecretKey skey, AgileEncryptor encryptor) at NPOI.POIFS.Crypt.Agile.AgileEncryptor.GetDataStream(DirectoryNode dir) at NPOI.POIFS.Crypt.Encryptor.GetDataStream(POIFSFileSystem fs)
Issue Description
Trying to prepare encrypted stream to be saved to file.