Skip to content

Commit

Permalink
encrypt refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jurczewski committed Apr 22, 2024
1 parent 7d7e38a commit f5fab2c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/PrivatePdfConverter/Commands/EncryptPdf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class EncryptPdf
public static void EncryptPdfWithPassword(string path, string password, string? output)
{
Log.Logger.Information("Read 1 file with name: {FileName}, Full path: '{Path}'", Path.GetFileName(path), path);

var outputFileName = output.PrepareOutputFileName();
var exportFullPath = $"{path}/{outputFileName}";

Expand All @@ -22,15 +23,16 @@ private static void EncryptPdfFile(string path, string password, string outputFi
{
var passwordBytes = Encoding.Default.GetBytes(password);

var pdfReader = new PdfReader(path);
using var pdfReader = new PdfReader(path);
var writerProperties = new WriterProperties()
.SetStandardEncryption(
passwordBytes,
passwordBytes,
EncryptionConstants.ALLOW_PRINTING,
EncryptionConstants.ENCRYPTION_AES_128);
var pdfWriter = new PdfWriter(new FileStream(outputFileName, FileMode.Create), writerProperties);
var pdfDocument = new PdfDocument(pdfReader, pdfWriter);
using var pdfWriter = new PdfWriter(new FileStream(outputFileName, FileMode.Create), writerProperties);
using var pdfDocument = new PdfDocument(pdfReader, pdfWriter);

pdfDocument.Close();
}
}

0 comments on commit f5fab2c

Please sign in to comment.