diff --git a/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document.sln b/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document.sln new file mode 100644 index 00000000..7725f2f8 --- /dev/null +++ b/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36408.4 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Decrypting-encrypted-PDF-document", "Decrypting-encrypted-PDF-document\Decrypting-encrypted-PDF-document.csproj", "{93EFCE7C-2111-4150-AB8D-5E675DADB782}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {93EFCE7C-2111-4150-AB8D-5E675DADB782}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {93EFCE7C-2111-4150-AB8D-5E675DADB782}.Debug|Any CPU.Build.0 = Debug|Any CPU + {93EFCE7C-2111-4150-AB8D-5E675DADB782}.Release|Any CPU.ActiveCfg = Release|Any CPU + {93EFCE7C-2111-4150-AB8D-5E675DADB782}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {ACAC9DFE-C228-4D63-BEB8-B3F16EDEA60F} + EndGlobalSection +EndGlobal diff --git a/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Data/Input.pdf b/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Data/Input.pdf new file mode 100644 index 00000000..51caf9b1 Binary files /dev/null and b/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Data/Input.pdf differ diff --git a/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Decrypting-encrypted-PDF-document.csproj b/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Decrypting-encrypted-PDF-document.csproj new file mode 100644 index 00000000..0aed398c --- /dev/null +++ b/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Decrypting-encrypted-PDF-document.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Decrypting_encrypted_PDF_document + enable + enable + + + + + + + diff --git a/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Output/gitkeep.txt b/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Output/gitkeep.txt new file mode 100644 index 00000000..e69de29b diff --git a/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Program.cs b/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Program.cs new file mode 100644 index 00000000..8d969eb5 --- /dev/null +++ b/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Program.cs @@ -0,0 +1,26 @@ +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + +using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +{ + // Load the encrypted PDF document from the input stream + PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream, "syncfusion"); + + // Set the document permissions to default (removes any restrictions) + loadedDocument.Security.Permissions = PdfPermissionsFlags.Default; + + // Clear the owner and user passwords to decrypt the document + loadedDocument.Security.OwnerPassword = string.Empty; + loadedDocument.Security.UserPassword = string.Empty; + + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) + { + // Save the decrypted PDF document to the output stream + loadedDocument.Save(outputStream); + } + // Close the loaded PDF document and release resources + loadedDocument.Close(true); +}