Hi, 
I am in stage of developing Encryption for the PDF files. 
I read a lot of mails on similar topic in archives, but could not lay hands on something complete or with correct values.  
 
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.
 
-------------------------------------------------------------------------------------

The information contained in this message is proprietary of Amdocs,

protected from disclosure, and may be privileged.

The information is intended to be conveyed only to the designated recipient(s)

of the message. If the reader of this message is not the intended recipient,

you are hereby notified that any dissemination, use, distribution or copying of 

this communication is strictly prohibited and may be unlawful. 

If you have received this communication in error, please notify us immediately

by replying to the message and deleting it from your computer.

Thank you.

---------------------------------------------------------

Reply via email to