nissl-lab / npoi

a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
Apache License 2.0
5.67k stars 1.43k forks source link

Encryptor.GetDataStream throws System.NullReferenceException #1275

Closed Quark321 closed 4 months ago

Quark321 commented 6 months ago

NPOI Version

2.6.2

File Type

any file even empty

Reproduce Steps

            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.

tonyqus commented 4 months ago

Encrypting file is not supported so far