0

I've encrypted some pdf files with iTextsharp lib and using AES 128bits and key length = 16bytes(protect reading).Can anyone break password or some app can do that? Thank so much.

The Bird
  • 397
  • 2
  • 8
  • 19
  • http://stackoverflow.com/questions/1110152/breaking-aes-encryption-using-decrypted-data this pretty much answers it – Mikey Apr 15 '12 at 15:10
  • thanks Mikey,but I'm using PDF encryption options of Adobe.I don't know it's the same with encrypt a file with AES 128bits or not? – The Bird Apr 15 '12 at 15:26
  • AES just means Advanced Encryption Standard - Adobe's version will adhere to the standard; either way - you're unlikely to crack it unless you have some serious computing power (think NSA supercomputer). – Mikey Apr 15 '12 at 15:42

1 Answers1

2

You can set 2 kinds of possible "passwords" here:

  • Read password
  • Edit/Modify password

Using an "edit password" is not secure at all, because it's possible to read the whole file (even without knowing the password, by using PdfReader.unethicalreading = true;) and then creating a new unencrypted one:

using System.IO;
using iTextSharp.text.pdf;

namespace PdfDecryptorCore
{
    public class PasswordDecryptor
    {
        public string ReadPassword { set; get; }        
        public string PdfPath { set; get; }
        public string OutputPdf { set; get; }

        public void DecryptPdf()
        {
            PdfReader.unethicalreading = true;

            PdfReader reader;
            if(string.IsNullOrWhiteSpace(ReadPassword))
             reader = new PdfReader(PdfPath);
            else
                reader = new PdfReader(PdfPath, System.Text.Encoding.UTF8.GetBytes(ReadPassword));

            using (var stamper = new PdfStamper(reader, new FileStream(OutputPdf, FileMode.Create)))
            {
                stamper.Close();
            }
        }
    }
}
VahidN
  • 18,457
  • 8
  • 73
  • 117