We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Detect signatures & encryption of file in memory stream

Hello,


how can I detect if a file is digitally signed and/or encrypted when this file is not stored on disk but stored online (SharePoint library) and is loaed into a MemoryStream?

As far I know “FileFormatUtil.DetectFileFormat” only works with locally stored docments.

To specify it a bit more:
I need to check if a document of any format (usually Microsoft Office, Open Office or pdf files or images, html or text files) is neither encrypted, password protected (if possible) nor digitally signed.

Thanks for your help.

.Net 3.5
M. Office 2010

Hi Bea,

Thank you for contacting support.

bea.grosse-venhaus:
As far I know “FileFormatUtil.DetectFileFormat” only works with locally stored docments.

The DetectFileFormat method of the FileFormatUtil class also takes a stream object. You can download the file stream and pass it as a parameter instead of the complete local path string.

Please refer to these help topics: Determine the Protection of a PDF, Determine the Encryption of an Excel and Determine the Protection of a Word Document

Please let us know in case of any further assistance or questions.

Thanks for yor reply.


How can I detect if a presentation (Aspose.Slides) is encrypted and/or digitally signed?

Is that your solution?
PDF:
PdfFileInfo info = new PdfFileInfo();
info.BindPdf(pdfConvMemoryStream);

if(info.IsEncrypted)
{
//error handling
}

pdfConvMemoryStream.Position = 0;

Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(pdfConvMemoryStream);

Aspose.Pdf.Facades.PdfFileSignature pdfSign = new Aspose.Pdf.Facades.PdfFileSignature(pdfDoc);
if(pdfSign.IsCertified)
{
//error handling
}

Cells:
Aspose.Cells.LoadOptions opt;
Aspose.Cells.FileFormatInfo info = Aspose.Cells.FileFormatUtil.DetectFileFormat(docMemoryStream);

if (info.IsEncrypted || info.IsProtectedByRMS)
{
//error handling
}

//Initialize LoadOptions containing LoadFormat
opt = new Aspose.Cells.LoadOptions(info.LoadFormat);

//Load document to Workbook
Workbook wb = new Workbook(docMemoryStream, opt);

if(wb.IsDigitallySigned || wb.Settings.IsProtected)
{
//error handling
}

Words:
Aspose.Words.FileFormatInfo info = Aspose.Words.FileFormatUtil.DetectFileFormat(docMemoryStream);
if(info.IsEncrypted || info.HasDigitalSignature)
{
//error handling
}
docMemoryStream.Position = 0;

Hi Bea,


Thank you for the inquiry. We’re working over your query and will get back to you soon.

Hi Bea,


Thank you for being patient.
bea.grosse-venhaus:
How can I detect if a presentation (Aspose.Slides) is encrypted and/or digitally signed?
You can detect the source presentation format and also check whether the presentation is encrypted or not. Please check this code example:
[.NET, C#]
// load a presentation
Presentation pres = new Presentation(@“c:\temp\MyPres.pptx”);
// get the file format
SourceFormat format = pres.SourceFormat;
// check the encryption of presentation
bool obj = pres.ProtectionManager.IsEncrypted;
bea.grosse-venhaus:
Is that your solution?
All the code examples are fine.
Please also refer to this help topic: Extract Signature Information from a PDF

In reference to the Aspose.Cells API, we have refined the code example as below:
[.NET, C#]
//Detect File format
FileFormatInfo info = FileFormatUtil.DetectFileFormat(“e:\test2\structure+protected.xls”);
//Gets the detected load format
Console.WriteLine("The spreadsheet format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat));
Console.WriteLine("The spreadsheet format is: " + info.LoadFormat.ToString());
//Check if the file is encrypted or not.
Console.WriteLine("The file is encrypted: " + info.IsEncrypted);

workbookObj.IsDigitallySigned property can be used to detect if the Workbook is digitally signed or not as you coded.

Please let us know in case of any confusion or questions.

How can I detect if files are read-only/write-protected?

Hi Bea,


Thank you for the inquiry. The Document class in the Aspose.Words API offers DocumentType property to retrieve the protection type of Word document.

In reference to the Aspose.Cells API, Workbook.Settings.IsEncrypted property will be true if the workbook is password protected, otherwise it’ll be false. Furthermore, as a workbook contains worksheets which can be set to read only therefore it can be checked by Worksheet.IsProtected property. Please check the code samples as below:

[.NET, C#]
<span style=“color: rgb(0, 128, 0); background-color: rgb(255, 255, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>// check whether the workbook is password protected
var wb = new Workbook(dataDir + “sample.xlsx”);
Console.WriteLine(wb.Settings.IsEncrypted);

// check whether the worksheet is readonly
var wb = new Workbook(dataDir + “sample.xlsx”);
Console.WriteLine(wb.Worksheets[0].IsProtected);

In reference to the Aspose.Pdf API, you can check the security type of a PDF as below:

[.NET, C#]
// get PDF information PdfFileInfo pdfFileInfo = new PdfFileInfo("input.pdf");
if (pdfFileInfo.HasOpenPassword ) Console.WriteLine("The given PDF file is password protected and has open password.");
if (pdfFileInfo.HasEditPassword) Console.WriteLine("The given PDF file is password protected and has owner password.");

Please let us now in case of any confusion or questions.

Thanks for the quick answer. Unfortuantely my question wasn’t specific enough - with read-only/write-protection I meant if someone sets this property in the Windows Explorer properties for the file that should be converted to PDF.

Hi Bea,

Thank you for the details. On reading the office files, Aspose APIs only load files in the main memory and don't alter until you don't save it in the secondary memory. However, if there is any operating system level restriction, then it'll throw an appropriate error on saving. Please let us know in case of any confusion or questions.

Hello,

how can I detect signatures of e-mail messages?
CheckSignatures(Stream) seems to be working with EML files only.


The main e-mail format I am dealing with is MSG.

Hi Bea,

Thank you for the inquiry. Please note, CheckSignature method also works for MSG files. Please try out your source email message file and let us know how that goes on your side. If it shows an error, then please send us a zip archive of your source MSG file, so that we could investigate it. Your response is awaited.