public void TestPasswordProtected() { String filePath = Path.Combine(TESTFILE_DIR, "PasswordProtectedDocument.docx"); using (Workshare.FCS.Lite.Interface.File file = new Workshare.FCS.Lite.Interface.File(filePath, filePath)) { FileType type = file.FileType; Assert.IsFalse(IsMacroDetected(type), "Encrypted docx can't be opened to check if it is macro enabled: " + filePath); Assert.IsFalse(IsTemplateDetected(type), "Encrypted docx can't be opened to check if it is a template: " + filePath); Assert.IsTrue(file.ReadPasswordProtected, "Should have detected read password in " + filePath); Assert.IsTrue(file.WritePasswordProtected, "Should have detected write password in " + filePath); Assert.IsFalse(file.CanOpenContent, "Should have detected some protection in " + filePath); } }
public void TestXSLXPasswordProtectedSheet() { String filePath = Path.Combine(TESTFILE_DIR, "TestFileSheetProtection.xlsx"); using (Workshare.FCS.Lite.Interface.File file = new Workshare.FCS.Lite.Interface.File(filePath, filePath)) { Assert.IsTrue(file.DocumentProtected, "Should have detected sheet protection in " + filePath); Assert.IsFalse(file.ReadPasswordProtected, "Shouldn't have detected read password in " + filePath); Assert.IsFalse(file.WritePasswordProtected, "Shouldn't have detected write password in " + filePath); } }
/// <summary> /// Creates a default encryption object given the object type /// </summary> private IContentEncryption CreateEncryptionObject(Attachment attachment, IContentEncryption defaultEncryptor) { IContentEncryption result = null; // Create an encryption object and associate it with the attachment's name Workshare.FCS.Lite.Interface.File file = new Workshare.FCS.Lite.Interface.File(attachment.File.FileName, attachment.File.DisplayName); switch (file.FileType) { case FileType.ZIP: result = new ZipEncryption(attachment, file); break; case FileType.WordDocument: case FileType.WordDocumentX: case FileType.WordDocumentMacroX: case FileType.WordDocumentTemplateX: case FileType.WordDocumentMacroTemplateX: case FileType.RTFDocument: result = new WordEncryption(attachment, file); break; case FileType.ExcelSheet: case FileType.ExcelSheetX: case FileType.ExcelSheetMacroX: case FileType.ExcelSheetTemplateX: case FileType.ExcelSheetMacroTemplateX: result = new ExcelEncryption(attachment, file); break; case FileType.PowerPoint: case FileType.PowerPointX: case FileType.PowerPointMacroX: case FileType.PowerPointTemplateX: case FileType.PowerPointMacroTemplateX: case FileType.PowerPointShowX: case FileType.PowerPointMacroShowX: if (!OfficeApplicationVersion.IsPowerPointXP()) { result = new PowerPointEncryption(attachment, file); } break; case FileType.PDFDocument: result = new PDFEncryption(attachment, file); break; } // See GetAssociatedEncryptionObject. // If teh file type has been changed by an action (e.g. PDF) then we recreate the encryption // object and copy over the old password fields. However, if we are zipping up the documents // then we aren't changing their file type and should not enrypt the container. if( defaultEncryptor != null && file.FileType != FileType.ZIP ) { // Copy across the passwords to the new encryption object result.ModifyPassword = defaultEncryptor.ModifyPassword; result.OpenPassword = defaultEncryptor.OpenPassword; result.AllowDefaultPassword = defaultEncryptor.AllowDefaultPassword; result.WasReadOnly = defaultEncryptor.WasReadOnly; } return result; }