// This function adds a zip encryption entry for a Zip Action content item. internal void AddZipActionEncryptor(string contentId, string filename, string password) { try { byte[] data = { 0 }; // Create a ZipEncryption to store the password. IContentEncryption encryption = new ZipEncryption( new Attachment(filename, "ZIP", contentId, "-1", false), new FCS.Lite.Interface.File(new SharedBinaryData(data), filename)) { OpenPassword = password }; AssociateEncryptorWithData(contentId, encryption); } catch (Exception e) { Logger.LogError(e); } }
/// <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; }