X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=pdf2swf%2Fxpdf%2FDecrypt.cc;h=91eb452a8152c50429c725ea6b5b9026ac5125f1;hp=dab075093c3b7ab5a16516a9026fb8d2952de89b;hb=85c46a8011c7fd5e4bda282266006c972ea7606b;hpb=b0d012f83219d898e9cd92281d9996bc9ff13b5f diff --git a/pdf2swf/xpdf/Decrypt.cc b/pdf2swf/xpdf/Decrypt.cc index dab0750..91eb452 100644 --- a/pdf2swf/xpdf/Decrypt.cc +++ b/pdf2swf/xpdf/Decrypt.cc @@ -12,6 +12,7 @@ #pragma implementation #endif +#include #include "gmem.h" #include "Decrypt.h" @@ -65,7 +66,8 @@ GBool Decrypt::makeFileKey(int encVersion, int encRevision, int keyLength, GString *ownerKey, GString *userKey, int permissions, GString *fileID, GString *ownerPassword, GString *userPassword, - Guchar *fileKey, GBool *ownerPasswordOk) { + Guchar *fileKey, GBool encryptMetadata, + GBool *ownerPasswordOk) { Guchar test[32], test2[32]; GString *userPassword2; Guchar fState[256]; @@ -110,7 +112,8 @@ GBool Decrypt::makeFileKey(int encVersion, int encRevision, int keyLength, } userPassword2 = new GString((char *)test2, 32); if (makeFileKey2(encVersion, encRevision, keyLength, ownerKey, userKey, - permissions, fileID, userPassword2, fileKey)) { + permissions, fileID, userPassword2, fileKey, + encryptMetadata)) { *ownerPasswordOk = gTrue; delete userPassword2; return gTrue; @@ -120,13 +123,15 @@ GBool Decrypt::makeFileKey(int encVersion, int encRevision, int keyLength, // try using the supplied user password return makeFileKey2(encVersion, encRevision, keyLength, ownerKey, userKey, - permissions, fileID, userPassword, fileKey); + permissions, fileID, userPassword, fileKey, + encryptMetadata); } GBool Decrypt::makeFileKey2(int encVersion, int encRevision, int keyLength, GString *ownerKey, GString *userKey, int permissions, GString *fileID, - GString *userPassword, Guchar *fileKey) { + GString *userPassword, Guchar *fileKey, + GBool encryptMetadata) { Guchar *buf; Guchar test[32]; Guchar fState[256]; @@ -136,7 +141,7 @@ GBool Decrypt::makeFileKey2(int encVersion, int encRevision, int keyLength, GBool ok; // generate file key - buf = (Guchar *)gmalloc(68 + fileID->getLength()); + buf = (Guchar *)gmalloc(72 + fileID->getLength()); if (userPassword) { len = userPassword->getLength(); if (len < 32) { @@ -154,7 +159,14 @@ GBool Decrypt::makeFileKey2(int encVersion, int encRevision, int keyLength, buf[66] = (permissions >> 16) & 0xff; buf[67] = (permissions >> 24) & 0xff; memcpy(buf + 68, fileID->getCString(), fileID->getLength()); - md5(buf, 68 + fileID->getLength(), fileKey); + len = 68 + fileID->getLength(); + if (!encryptMetadata) { + buf[len++] = 0xff; + buf[len++] = 0xff; + buf[len++] = 0xff; + buf[len++] = 0xff; + } + md5(buf, len, fileKey); if (encRevision == 3) { for (i = 0; i < 50; ++i) { md5(fileKey, keyLength, fileKey);