Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Crypto - RC4
Message
De
04/03/2003 15:30:00
 
 
À
04/03/2003 15:12:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00759999
Message ID:
00761156
Vues:
21
>>>Alex,
>>
>>Thanks for the answer. I am still on vfp6 (though I have vfp7 in my cupboard since a few months, haven't had the time yet), so I have not got ffc\_crypt.vcx.
>>
>>To explain further. I am not after encrypting a whole pdf file. The pdf I produce and encrypt must be read by AcrobatReader. Hence, I have to adhere to their principles
>>
>>In a pdf file, the strings and streams may be encrypted to protect from modification, printing, and the like.
>>
>>This is done with an algorithm described in the pdf reference manual ( algorithm below, manual is +/- 1000 pages http://partners.adobe.com/asn/developer/acrosdk/docs/filefmtspecs/PDFReference.pdf (page 73)
>>
>>Where I am stuck is point 4.:
>>
>>Algorithm 3.1 Encryption of data using an encryption key
>>
>>1. Obtain the object number and generation number from the object identifier of
>>the string or stream to be encrypted (see Section 3.2.9, “Indirect Objects”). If the
>>string is a direct object, use the identifier of the indirect object containing it.
>>
>>2. Treating the object number and generation number as binary integers, extend the
>>original n-byte encryption key to n + 5 bytes by appending the low-order 3 bytes
>>of the object number and the low-order 2 bytes of the generation number in that
>>order, low-order byte first. (n is 5 unless the value of V in the encryption dictionary
>>is greater than 1, in which case n is the value of Length divided by 8.)
>>
>>3. Initialize the MD5 hash function and pass the result of step 2 as input to this function.
>>
>>4. Use the first (n + 5) bytes, up to a maximum of 16, of the output from the MD5
>>hash as the key for the RC4 encryption function, along with the string or stream
>>data to be encrypted. The output is the encrypted data to be stored in the PDF file.
>>
>>I can use the crypto API to generate the Encryption key as a start for point 1. (page 78, algorithm 3.2).
>>From point 1. I can get to 3. using crypto api
>>
>>The problem is point 4 where I have to feed a variable length key to the RC4. That key is a part of the key generated in point 3.
>>
>>I can do that with a program, I just do not know how to get that key into the crypto api, so that the CryptoEncrypt/CryptoDecrypt uses that key.
>>
>>As far as I can see, CryptDeriveKey() won't work.
>>
>>Just hoped there might be a possibility. If there isn't, tough, I'll use the program
>>
>>as an example (all in hex)
>>
>>IN   3EF00938B4C591A254B911A5D25432F8B73848CB
>>KEY  CCF0A3B5D1A558E99ED3
>>Out  4889AC555B6FDA30187DCFAFF0237BA8E3FB65AA
>>
>>
>>Of course, I may have overlooked something

>
>I have not used PDFs in more than the basics (i.e. printing an .FRX to .PDF in my websites). I haven't had to deal with PDF security and encryption. I would have to research this to be able to help.
>
>Rick Schummer has a series of articles on PDF in the last 4 issues of Foxtalk (four parts). You may want to check those. I'll re-read them to see if they shed any light, or maybe you can ping Rick.

Alex,

Think I have cracked the pdf part (painfully).

I would prefer to use CryptoEncrypt()/CryptoDecrypt() of the crypto api if only I knew how to set a key for the RC4 algorithm. (see example above)

If not, I can always fall back on a vfp function I have written

In case I find a solution, I'll post it

Thanks for your help
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform