开发者

Encrypting PDF Document with C# [closed]

开发者 https://www.devze.com 2023-03-30 10:50 出处:网络
Closed. This question is seeking recommendati开发者_Python百科ons for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question is seeking recommendati开发者_Python百科ons for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 5 years ago.

Improve this question

is it possible to encrypt the content of a pdf with a symmetric encryption? and does acrobat etc. support the decryption automatically?

i need an api in c#/.net to encrypt the content of the file!

Kind Regard Michael


The Atalasoft PDF library (part of dotImage) can handle encryption or decryption of PDF documents for you (disclaimer, I work for Atalasoft and wrote the library). The code is very simple:

public void EncryptPdf(Stream input, Stream output, string userPassword, string ownerPassword)
{
    if (input == output) throw new ArgumentExeption("input", "input and output must be different");
    PdfDocument doc = new PdfDocument(input);
    // at this point if you set doc.Permissions, you can fine-control what can be
    // done to the document.  If userPassword is null, then the document can be opened
    // without a password prompt, but will be restricted to the permissions.
    // Permissions includes things like Printing, Modifying, Copying Text etc.
    doc.Save(userPassword, ownerPassword, output);
}


Docotic.Pdf library can encrypt or decrypt PDF files for you.

PDF Reference defines two standard encryption algorithms: RC4 and AES. Both algorithms are symmetric. RC4 uses keys with 40 to 128 bits length. AES uses 128 bit keys (256 keys are to become new standard soon).

Encrypted PDFs can be completely locked (you and anyone else won't be able to open them without password) or just "protected" from modifications (anyone will be able to open them without any password and well-behaved viewers won't allow to change them).

Please take a look at sample that shows how to encrypt PDF document with AES 128 bit.

Disclaimer: I work for Bit Miracle, vendor of the library.


You don't want to do this sort of thing manually, rather you want to use a PDF library.

I do not know if there are those which support the native/Adobe PDF encryption but you can take a look at some of them and check their features.


Yes, using certificates.

http://help.adobe.com/en_US/Acrobat/9.0/Standard/WS58a04a822e3e50102bd615109794195ff-7d6c.w.html

If you've paid for a fully featured version of Acrobat you can use its JavaScript interface to do the work for you (although it looks an effort in itself.)

It seems iTextSharp can do it with or without a certificate and is Open Source so might be a good choice. They certainly make a point of presenting thier book as a good resource. This was the first third party library I looked at, other suppliers may offer these features.

However, if you want to automate the process and you don't want to pay Adobe or some other 3rd party, I hope somebody provides a more complete answer.

Here is a link to the definition of the PDF file format.

0

精彩评论

暂无评论...
验证码 换一张
取 消