示例#1
0
        public static void AssertProtection(string filePath, FileAuthentication fileAuth, AuthenticationManager authenticationManager,
                                            bool expectedIsEncrypted,
                                            bool expectedDontEncryptMetadata,
                                            bool expectedAllowAssembly          = false,
                                            bool expectedAllowCopy              = false,
                                            bool expectedAllowDegradedPrinting  = false,
                                            bool expectedAllowFillIn            = false,
                                            bool expectedAllowModifyAnnotations = false,
                                            bool expectedAllowModifyContents    = false,
                                            bool expectedAllowPrinting          = false,
                                            bool expectedAllowScreenReaders     = false)
        {
            using (var comparer = new PdfComparer(filePath, fileAuth, authenticationManager))
            {
                Assert.AreEqual(expectedIsEncrypted, comparer.pdfReader.IsEncrypted());
                Assert.AreEqual(expectedDontEncryptMetadata, !comparer.pdfReader.IsMetadataEncrypted());

                if (expectedAllowAssembly && expectedAllowCopy && expectedAllowDegradedPrinting && expectedAllowFillIn &&
                    expectedAllowModifyAnnotations && expectedAllowModifyContents && expectedAllowPrinting && expectedAllowScreenReaders)
                {
                    Assert.IsTrue(comparer.pdfReader.IsOpenedWithFullPermissions);
                }
                else
                {
                    Assert.AreEqual(expectedAllowAssembly, PdfEncryptor.IsAssemblyAllowed((int)comparer.pdfReader.Permissions));
                    Assert.AreEqual(expectedAllowCopy, PdfEncryptor.IsCopyAllowed((int)comparer.pdfReader.Permissions));
                    Assert.AreEqual(expectedAllowDegradedPrinting, PdfEncryptor.IsDegradedPrintingAllowed((int)comparer.pdfReader.Permissions));
                    Assert.AreEqual(expectedAllowFillIn, PdfEncryptor.IsFillInAllowed((int)comparer.pdfReader.Permissions));
                    Assert.AreEqual(expectedAllowModifyAnnotations, PdfEncryptor.IsModifyAnnotationsAllowed((int)comparer.pdfReader.Permissions));
                    Assert.AreEqual(expectedAllowModifyContents, PdfEncryptor.IsModifyContentsAllowed((int)comparer.pdfReader.Permissions));
                    Assert.AreEqual(expectedAllowPrinting, PdfEncryptor.IsPrintingAllowed((int)comparer.pdfReader.Permissions));
                    Assert.AreEqual(expectedAllowScreenReaders, PdfEncryptor.IsScreenReadersAllowed((int)comparer.pdfReader.Permissions));
                }
            }
        }
示例#2
0
        public Dictionary <string, string> GetEncryptionInfo()
        {
            string hexValue = string.Empty;
            Dictionary <string, string> EncryptionInfo = new Dictionary <string, string>();

            EncryptionInfo.Add("IsEncrypted", EncryptionRecordInfo.isEncrypted.ToString());
            if (EncryptionRecordInfo.isEncrypted)
            {
                EncryptionInfo.Add("pdfVersion", EncryptionRecordInfo.pdfVersion.ToString());
                EncryptionInfo.Add("rValue", EncryptionRecordInfo.rValue.ToString());
                EncryptionInfo.Add("encryptionType", EncryptionRecordInfo.encryptionType.ToString());
                EncryptionInfo.Add("keyLength", EncryptionRecordInfo.keyLength.ToString());
                EncryptionInfo.Add("metadataIsEncrypted", EncryptionRecordInfo.metadataIsEncrypted.ToString());
                EncryptionInfo.Add("Password charset", EncryptionRecordInfo.PasswordCharset.ToString());
                EncryptionInfo.Add("Max password size", EncryptionRecordInfo.MaxPasswordSize.ToString());
                EncryptionInfo.Add("User password is set", UserPasswordIsSet.ToString());
                if (UserPasswordIsSet)
                {
                    EncryptionInfo.Add("User password found", RecoveredUserPassword);
                }
                EncryptionInfo.Add("Owner password is set", OwnerPasswordIsSet.ToString());
                if (OwnerPasswordIsSet)
                {
                    EncryptionInfo.Add("Owner password found", RecoveredOwnerPassword);
                }

                hexValue = string.Empty;
                foreach (byte b in EncryptionRecordInfo.documentID)
                {
                    hexValue += string.Format("{0:X02} ", b);
                }
                EncryptionInfo.Add(string.Format("documentID({0} bytes)", EncryptionRecordInfo.documentID.Length), hexValue);
                hexValue = string.Empty;
                foreach (byte b in EncryptionRecordInfo.oValue)
                {
                    hexValue += string.Format("{0:X02} ", b);
                }
                EncryptionInfo.Add(string.Format("oValue({0} bytes)", EncryptionRecordInfo.oValue.Length), hexValue);
                hexValue = string.Empty;
                foreach (byte b in EncryptionRecordInfo.uValue)
                {
                    hexValue += string.Format("{0:X02} ", b);
                }
                EncryptionInfo.Add(string.Format("uValue({0} bytes)", EncryptionRecordInfo.uValue.Length), hexValue);

                EncryptionInfo.Add("pValue", EncryptionRecordInfo.pValue.ToString());
                EncryptionInfo.Add("Modify annotations",
                                   PdfEncryptor.IsModifyAnnotationsAllowed((int)EncryptionRecordInfo.pValue) ? "Allowed" : "Not allowed");
                EncryptionInfo.Add("Modify content",
                                   PdfEncryptor.IsModifyContentsAllowed((int)EncryptionRecordInfo.pValue) ? "Allowed" : "Not allowed");
                EncryptionInfo.Add("Printing",
                                   PdfEncryptor.IsPrintingAllowed((int)EncryptionRecordInfo.pValue) ? "Allowed" : "Not allowed");
                EncryptionInfo.Add("Screen readers",
                                   PdfEncryptor.IsScreenReadersAllowed((int)EncryptionRecordInfo.pValue) ? "Allowed" : "Not allowed");
                EncryptionInfo.Add("Degraded printing",
                                   PdfEncryptor.IsDegradedPrintingAllowed((int)EncryptionRecordInfo.pValue) ? "Allowed" : "Not allowed");
                EncryptionInfo.Add("Fill In",
                                   PdfEncryptor.IsFillInAllowed((int)EncryptionRecordInfo.pValue) ? "Allowed" : "Not allowed");
                EncryptionInfo.Add("Copy",
                                   PdfEncryptor.IsCopyAllowed((int)EncryptionRecordInfo.pValue) ? "Allowed" : "Not allowed");
                EncryptionInfo.Add("Assembly",
                                   PdfEncryptor.IsAssemblyAllowed((int)EncryptionRecordInfo.pValue) ? "Allowed" : "Not allowed");
            }
            return(EncryptionInfo);
        }
示例#3
0
        public int GetProperties(out Dictionary <string, string> fileProperties,
                                 out Dictionary <string, string> info,
                                 out Dictionary <string, string> security)
        {
            int result = Define.Failure;
            Dictionary <string, string> properties   = null;
            Dictionary <string, string> fileSecurity = null;

            try
            {
                properties   = new Dictionary <string, string>();
                fileSecurity = new Dictionary <string, string>();
                properties.Add("Name", Info.Name);
                properties.Add("Pdf version", Reader.PdfVersion.ToString());
                properties.Add("Number of pages", Reader.NumberOfPages.ToString());
                properties.Add("DirectoryName", Info.DirectoryName);
                properties.Add("Length", Info.Length.ToString() + "(bytes)");
                properties.Add("IsReadOnly", Info.IsReadOnly.ToString());
                properties.Add("CreationTime", Info.CreationTime.ToString());
                properties.Add("LastAccessTime", Info.LastAccessTime.ToString());
                properties.Add("LastWriteTime", Info.LastWriteTime.ToString());

                fileSecurity.Add("Is encrypted", Reader.IsEncrypted().ToString());
                fileSecurity.Add("Is 128Key", Reader.Is128Key().ToString());
                fileSecurity.Add("Full permissions", Reader.IsOpenedWithFullPermissions.ToString());
                string sVal = PdfEncryptor.IsModifyAnnotationsAllowed((int)Reader.Permissions) ? "Allowed" : "Not allowed";
                fileSecurity.Add("Modify annotations", sVal);
                sVal = PdfEncryptor.IsModifyContentsAllowed((int)Reader.Permissions) ? "Allowed" : "Not allowed";
                fileSecurity.Add("Modify content", sVal);
                sVal = PdfEncryptor.IsPrintingAllowed((int)Reader.Permissions) ? "Allowed" : "Not allowed";
                fileSecurity.Add("Printing", sVal);
                sVal = PdfEncryptor.IsScreenReadersAllowed((int)Reader.Permissions) ? "Allowed" : "Not allowed";
                fileSecurity.Add("Screen readers", sVal);
                sVal = PdfEncryptor.IsDegradedPrintingAllowed((int)Reader.Permissions) ? "Allowed" : "Not allowed";
                fileSecurity.Add("Degraded printing", sVal);
                sVal = PdfEncryptor.IsFillInAllowed((int)Reader.Permissions) ? "Allowed" : "Not allowed";
                fileSecurity.Add("Fill In", sVal);
                sVal = PdfEncryptor.IsCopyAllowed((int)Reader.Permissions) ? "Allowed" : "Not allowed";
                fileSecurity.Add("Copy", sVal);
                sVal = PdfEncryptor.IsAssemblyAllowed((int)Reader.Permissions) ? "Allowed" : "Not allowed";
                fileSecurity.Add("Assembly", sVal);

                result = Define.Success;
            }
            catch (Exception ex)
            {
                ErrorMsg = ex.Message;
                result   = Define.Failure;
            }

            if (result == Define.Success)
            {
                info = Reader.Info;
            }
            else
            {
                if (properties != null)
                {
                    properties.Clear();
                    properties = null;
                }

                if (fileSecurity != null)
                {
                    fileSecurity.Clear();
                    fileSecurity = null;
                }

                info = null;
            }

            fileProperties = properties;
            security       = fileSecurity;
            return(result);
        }