Planet PDF Forum Archive

Planet PDF ForumWowsers! This is page is old, head to the LIVE Planet PDF Forum. It features more than 10 conferences, covering everything from beginner to in-depth developer and pre-press discussions. If you wish to continue... one & two archive covers 1999-2011 (160,000 pages).


New Forum | Previous | Next | (P-PDF) Developers


Topic: PDF Encryption
Conf: (P-PDF) Developers, Msg: 102954
From: shantanu
Date: 12/27/2003 12:33 AM

Hi,
I am in stage of developing Encryption for the PDF files.
Reference is taken from PDF reference 1.4. I have taken demo version of RSA md5 and rc4 functions.
So far so good.
Now I need desperate help.
Some how I am not able to generate correct user password (even if I give blank passwords, though I am able to get correct owner password)
I am attaching my piece of code which does this and also step wise results.
If anybody has the correct set of values, please please send it to me.

----NO PASSWORD CASE---

Generating Owner Password

/* this is the string used when the pass is less than 32 bytes */
unsigned char PDF_ENCRYP_STR[] = {
0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A
};
#define SUCCESS 0

int _npdfGenerateOwnPass()
{
int status = SUCCESS;

do {
status = _npdfmd5(PDF_ENCRYP_STR, 32, Outstr);
if (status)
break;

/* First 5 characters should be taken for Rev. 2 */
memcpy((void *)ownKeyData, (void *)Outstr,5);
ownKeyDataLen = 5;

status = _npdfrc4(ownKeyData, ownKeyDataLen, PDF_ENCRYP_STR, encrypData, &encrypDataLen);
if(status) {
printf("\n Problem in Encrypting Owner Password");
break;
}

memcpy(nPdf.ownerpass,encrypData,encrypDataLen);

} while (0);
return status;
}

The entry that comes in encrypData is 16 bytes :
20 55 c7 56 c7 2e 1a d7 02 60 8e 81 96 ac ad 44 7a d3 2d 17 cf f5 83 23 5f 6d d1 5f ed 7d ab 67

Now I generate Encryption Key-

int _npdfComputeEncrKey(unsigned char *passwd)
{
int status = SUCCESS;
unsigned char fileID[]="b77d83b503429690d1ca764e117d5f68";
unsigned char keyStr[100];
unsigned char permissionEntry[] = {0xFC, 0xFF, 0xFF, 0xFF}; /* for permission -4 */
memcpy(keyStr,PDF_ENCRYP_STR,32);
memcpy(keyStr+32,ownKeyData,32);
memcpy(keyStr+64,permEntry,4);
memcpy(keyStr+68,fileID,32);
status = _npdfmd5(keyStr, 100, outStr);
if (status) {
printf("\n Problem in Computing the key");
return status;
}
return status;
}

Key - ed 4a 85 a1 9c a0 df 40 d0 59 ca 39 9c a3 6d 3f

Using the first five for creating the key - ed 4a 85 a1 9c

int _npdfGenerateUserPass()
{
int status;
unsigned char UsrKeyData[]={0xED,0x4A,0x85,0xA1,0x9C}
UsrKeyDataLen = 5;
status = _npdfrc4(UsrKeyData, UsrKeyDataLen , PDF_ENCRYP_STR, encrypData, &encrypDataLen);
if(status) {
printf("\n Unable to Encrypt User Password");
}
memcpy(nPdf.userpass,encrypData,encrypDataLen);
return status;
}

The User password comes out to be
6f fe b2 77 99 be 8d 32 7e 5f 8f 66 6e 91 3d 26 69 a0 13 6c 6b 0c 08 0e 02 b5 11 c1 b6 a2 ee 96


After doing this, when I open the doc in Acrobat, its asks for password, whereas I have not given any.
I am not understanding where am I goofing up. I am in need of desperate help, if anybody has any idea regarding this let me know.

Thanking you in anticipation,

Shantanu Kulkarni.



PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link...

Download free demo

Debenu PDF Tools Pro

It's simple to use and will let you preview and edit PDF files, it's a Windows application that makes...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.