How to determine if Powerpoint presentations are password protected?


#1

We need to detect if a presentation is password protected without loading it - for spreadsheets and word documents we use:

Aspose.Cells.FileFormatUtil.DetectFileFormat(filePath).IsEncrypted

Aspose.Words.FileFormatUtil.DetectFileFormat(filePath).IsEncrypted

How do we do the same for powerpoint presentations (for both 97-2003 and 2007 onwards file formats)?


How to know whether ppt is encrypted by using aspose.slides for .net
#2

Hi,

I have observed the requirement shared by you and like to share that you can also identify using Aspose.Slides that if the presentation is encrypted or not. Please try using the following sample code on your end.

Presentation.ProtectionManager.IsEncrypted

Please share, if I may help you further in this regard.

Many Thanks,

#3

Hi,

As mentioned above, for performance reasons we need to do this without loading the entire document - as far as I can tell the above code requires the document to be loaded first? If so how do we replicate the above calls for word and excel docs (that don't appear to load the document into memory)?


#4

Hi Dhanraj,


I like to share in that case you can try opening the presentation in try catch block without supplying password. In this case the exception will be thrown in this regard and you can handle that to serve the purpose on your end.

Many Thanks,

#5

That’s how we started out doing it, before discovering the above APIs. It isn’t performant because if the document isn’t password protected Aspose then proceeds to load the entire document into memory. Our goal is to quickly detect if a document is protected, but at this stage of our process we do not have the time to load the document (we could be checking up to 20 potentially large documents at once).


#6

Hi Dhanraj,

I have observed the requirement shared and regret to share that at present the support for identifying if the presentation is encrypted or not without loading it is unavailable in Aspose.Slides. I have created an issue with ID SLIDESNET-35379 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved.

We are sorry for your inconvenience,


#7

Is there any way can we find out when this will be implemented?


#8

Hi Dhanraj,

I like to share that you will be automatically notified once the support will be available via email address that is registered with us. The notification will also be included in this forum thread as well.

Many Thanks,


#9

The issues you have found earlier (filed as SLIDESNET-35379) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

#10

I see this got fixed but I dont’ see the code reference of how this can be done.


#11

@jojoshua,

I suggest you to please try using following sample code on your end.

IPresentationInfo info;

info = PresentationFactory.Instance.GetPresentationInfo(m_rootFolder + "\\Password\\open.ppt");
Assert.AreEqual(info.LoadFormat, LoadFormat.Ppt);
Assert.IsFalse(info.IsEncrypted);

info = PresentationFactory.Instance.GetPresentationInfo(m_rootFolder + "\\Password\\pwd.ppt");
Assert.AreEqual(info.LoadFormat, LoadFormat.Ppt);
Assert.IsTrue(info.IsEncrypted);

info = PresentationFactory.Instance.GetPresentationInfo(m_rootFolder + "\\Password\\open.pptx");
Assert.AreEqual(info.LoadFormat, LoadFormat.Pptx);
Assert.IsFalse(info.IsEncrypted);

info = PresentationFactory.Instance.GetPresentationInfo(m_rootFolder + "\\Password\\pwd.pptx");
Assert.AreEqual(info.LoadFormat, LoadFormat.Pptx);
Assert.IsTrue(info.IsEncrypted);

info = PresentationFactory.Instance.GetPresentationInfo(m_rootFolder + "\\Password\\open.odp");
Assert.AreEqual(info.LoadFormat, LoadFormat.Odp);
Assert.IsFalse(info.IsEncrypted);

info = PresentationFactory.Instance.GetPresentationInfo(m_rootFolder + "\\Password\\pwd.odp");
Assert.AreEqual(info.LoadFormat, LoadFormat.Odp);
Assert.IsFalse(info.IsEncrypted); // ODP verification hast not implemented yet.

#12

Thank you for the information. I tested this and have an issue with it. For Aspose.Words and Aspose.Cells, I am using code like this reading a memory stream to determine if it is encrypted.

  var wordInfo = Aspose.Words.FileFormatUtil.DetectFileFormat(file.InputStream);
          var  isEncrypted = wordInfo.IsEncrypted;

       var excelinfo = Aspose.Cells.FileFormatUtil.DetectFileFormat(file.InputStream);
            isEncrypted = excelinfo.IsEncrypted;       

This works well. However using the following code consumes my input stream and I can no longer read it like the other 2 examples. Please advise.
IPresentationInfo info;
info = PresentationFactory.Instance.GetPresentationInfo(file.InputStream);
isEncrypted = info.IsEncrypted;


#13

@jojoshua,

I have observed your following comments and have not been able to completely understand the issue shared.

Can you please share details of what issue is incurring so that I may help you further.


#14

It appears that using this code does not work the same way as determining if Word or Excel is encrypted. The following code appears to actually open the stream and causes subsequent code to not be able to read file.InputStream anymore. It seems that the Aspose.Words and Aspose.Cells using FileFormatutil.DetectFileFormat is not loading the whole file or at least not reading the stream to where it cannot be read by subsequent code. Does this make sense?

info = PresentationFactory.Instance.GetPresentationInfo(file.InputStream);
isEncrypted = info.IsEncrypted;

///reading from file.InputStream after the above code won’t work.


#15

@jojoshua,

I have tried loading the file using streams and it seems to work on my end using Aspose.Slides for .NET 18.5. I suggest you to please visit this image link for your kind reference as well.


#16

Check the InputStream.Position field. Notice that using Aspose.Words and Aspose.Cells methods that the InputStream.Position stays at 0. Using Aspose.Slides the position is altered and cannot be re-read. This also means that it is doing more work and is likely using more resources to determine if the file is encrypted.Capture.PNG (8.3 KB)


#17

@jojoshua,

I have observed your following comments.

For Aspose.Slides, you have to set the stream position to 0 before using that and the streams in Aspose.Slides are implemented this way. I am unable to get how more work or likely more resources are required for this as this is not a big process to set the stream position.


#18

So are you saying that if this was a 100mb powerpoint, this won’t load the entire file to determine if encrypted?


#19

@jojoshua,

Actually, FileStream constructor itself doesn’t load file into memory. PresentationInfo object is not a “presentation loaded into memory”, but it is a “metadata of presentation loaded into memory”. Metadata of presentation is much smaller than presentation. Also, after GetPresentationInfo(Stream stream) you can free FileStream:

using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read))
{ return GetPresentationInfo(stream, new FileInfo(file)); }

Internally, while executing GetPresentationInfo(Stream stream) we read FileStream and use some memory. But we have optimized memory consumption in this place. And memory consumption must be small while this call. If there is really big memory consumption that you have observed then you can share all related information with us and we may investigate that further.


#20

Thank you for the detailed explanation! We will use this without fear.