Hi,
I am developing a application in which I am creating PDF files using PDF specifications given in PDF 1.3. All things are working, for data encryption I am using FlateDecode. Now I have to implement password protection in PDF. I read complete specification regarding this. I want to use standard security handler for this. I implemented this also. I am giving both user and owner password to PDF, but still I am not able to open this file.
For owner password I am using following steps if anyone implemented this please check it and let me know.
For owner password:
1) I gave "jain"
2)after padding it is
jain(¿N^NuŠAd.NVÿú.....¶Ðh>€/.©þ
for padding I used
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
3)MD5 hash this
output is Qåý†ÜzùÀù 7 Õ¹Î`
4)Get the 5 byte key for rc4 algo
it is Qåý†Ü
5)get the user password "atul"
6) after padding it is atul(¿N^NuŠAd.NVÿú.....¶Ðh>€/.©þ
7)call the rc4 algo as
CryptAcquireContext (&vCryptProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
CryptCreateHash (vCryptProv, CALG_MD5, 0, 0, &vHashObj);
CryptHashData (vHashObj, (unsigned char*)pEncKey, 5, 0);
CryptDeriveKey (vCryptProv, CALG_RC4, vHashObj, CRYPT_EXPORTABLE, &vSessionKey);
CryptEncrypt (vSessionKey, 0, TRUE, 0, (unsigned char*)rawdata, pEncMsgLen, rawdatalen);
8) so final owner entry is
õ¶hÈHWVtMº|émÊöó^g(æO¨&LÔMYûÜý—
but I don't know whether it is correct or not, If u can please verify these steps and let me know.