Archive for the 'iText' Category

An Bug of iText and iTextSharp

Somebody sent me a encrypted PDF to ask me help decrypt, I tried pdfcrypt, it got error. and when used pdfcrack, got the following warning messages,

WARNING: O-String != 32 Bytes: 33
WARNING: U-String != 32 Bytes: 33

After studied the source code of iTextSharp, I noticed it is a bug of iTextSharp in SetupGlobalEncryptionKey method of the PdfEncryption class,
misused the this.ownerKey and ownerKey and we can only find this bug when the PDF has strange length of ownerkey/userkey, for example 33, not 32.

this.documentID = documentID;
//this.ownerKey = ownerKey;
Array.Copy(ownerKey, 0, this.ownerKey, 0, 32);
this.permissions = permissions;
// use variable keylength
mkey = new byte[keyLength / 8];

//fixed by ujihara in order to follow PDF refrence
md5.Reset();
md5.BlockUpdate(userPad, 0, userPad.Length);
//md5.BlockUpdate(ownerKey, 0, ownerKey.Length);
md5.BlockUpdate(this.ownerKey, 0, this.ownerKey.Length);

Then I review iText 5.1.1 and find it has the same bug:

this.documentID = documentID;
//this.ownerKey = ownerKey;
System.arraycopy(ownerKey, 0, this.ownerKey, 0, 32);
this.permissions = permissions;
// use variable keylength
mkey = new byte[keyLength / 8];

// fixed by ujihara in order to follow PDF reference
md5.reset();
md5.update(userPad);
//md5.update(ownerKey);
md5.update(this.ownerKey);

Be Sociable, Share!

Remove PDF Password Online -Google App Engine

After made iText worked on Google App Engine, I built Another application, Remove PDF Password Online. It bases on iText 2.1.7 but with many modification.

the main features of pdfdecrypt online are,

  • remove restrictions on any secured PDF document (you should have the right to do it, for example, if you forgot the password). Any Acrobat version up to 9 is supported, even with 128-bit AES or 128-bit RC4 encryption. PDF restrictions removal is an instant process. Unlocked file can be opened in any PDF viewer without any restrictions so you may edit/copy/print it.
  • remove the PDF open password. Decryption of the file with password for opening is guaranteed for PDF files Any Acrobat version up to 9 is supported, even with 128-bit AES or 128-bit RC4 encryption,but you must know the password first.

It supports upload PDF documents from your disk and give a PDF url.

If you like it, just have a try now, it is free.

Be Sociable, Share!

How to run iText on Google App Engine

Important update:

The last version itext-gae hosts at GitHub now, with many changes,

  • update to iText 4.2.0
  • fixs many bugs
  • supports Graphics2D now

Have applied Google App Engine (aka GAE) for a long time, recently I thought maybe I can build some PDF manipulation services on GAE, and I am familiar with iText, so I decide to try iText on GAE.

after some search, I got the following solution,

iText has dependencies on certain Java classes (java.awt.Color, java.nio.MappedByteBuffer etc.) which are ** not ** allowed by the Google
App Engine runtime .
Google App Engine throws an exception e.g “java.lang.NoClassDefFoundError: java.nio.MappedByteBuffer is a restricted class. Please see the Google App
Engine developer’s guide for more details.” is thrown for the unsupported class(es).
- Would it be possible to remove the dependency by iText on these Java classes, so as to enable the library to work within Google AppEngine?
See attached (very rough) Subversion patch file, for how I quickly removed some of the dependencies, so as to get iText to process a PDF form within
Google App Engine.

You can download the patch here,iText patch for GoogleAppEngine support.

And if you are very lazy, you can try directly download the modified version iText-2.1.7 (both jar and source)from here,

notice, iText-2.1.7-gae.jar forgot cmap_info.txt and glyphlist.txt, so if you directly use iText-2.1.7-gae.jar, you need add cmap_info.txt and glyphlist.txt to it first.

I have write two little demos and deployed them on my GAE home page, feel free to have a look here,
http://rubypdf.appspot.com

reference,
http://code.google.com/appengine/docs/java/jrewhitelist.html
iTextをGoogle App Engineから利用できるiText-gaeを公開しました
http://1t3xt.info/examples/browse/index.php

P.S.
Dec 21,2009, Release my first Google App Engine Application,Remove PDF Password Online, for introduce, please visit here.

Be Sociable, Share!