Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Crypt filter in streams #27

Closed
gunnsth opened this issue Sep 20, 2018 · 2 comments
Closed

Add support for Crypt filter in streams #27

gunnsth opened this issue Sep 20, 2018 · 2 comments
Labels
core Package core encoding/other enhancement New feature or request

Comments

@gunnsth
Copy link
Contributor

gunnsth commented Sep 20, 2018

Current state

PDF has a feature where streams can be encrypted with a crypt filter that is specified via DecodeParms that refers to the /CF dictionary of the /Encrypt dictionary. If DecodeParms is missing the Identity filter is used (raw data unchanged)

From 7.6.5 Crypt Filters (PDF32000_2008.PDF):

A stream filter type, the Crypt filter (see 7.4.10, "Crypt Filter") can be specified for any stream in the
document to override the default filter for streams.

For example here is a case where /Crypt is specified and DecodeParms is missing (Identity filter) so the data is left in tact. Seems to be used for metadata sometimes.

165 0 obj<</Length 3575/Filter[/Crypt]/Type/Metadata/Subtype/XML>>stream^M
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>

Another example from PDF32000_2008.PDF (p. 77)

5 0 obj
<< /Title ($#*#%*$#^&##) >> % Info dictionary: encrypted text string
endobj
6 0 obj
<< /Type /Metadata
/Subtype /XML
/Length 15
/Filter [/Crypt] % Uses a crypt filter
/DecodeParms % with these parameters
<< /Type /CryptFilterDecodeParms
/Name /Identity % Indicates no encryption
>>
>>
stream
XML metadata % Unencrypted metadata
endstream
endobj
8 0 obj % Encryption dictionary
<< /Filter /MySecurityHandlerName
/V 4 % Version 4: allow crypt filters
/CF % List of crypt filters
<< /MyFilter0
<< /Type /CryptFilter
/CFM V2 >> % Uses the standard algorithm
>>
/StrF /MyFilter0 % Strings are decrypted using /MyFilter0
/StmF /MyFilter0 % Streams are decrypted using /MyFilter0
... % Private data for /MySecurityHandlerName
/MyUnsecureKey (12345678)
/EncryptMetadata false
>>
endobj

Proposed change

Add support for supporting the Crypt filter in a similar fashion as other stream filters in core/stream.go

@gunnsth gunnsth transferred this issue from unidoc/unidoc May 24, 2019
@gunnsth gunnsth added enhancement New feature or request core Package core encoding/other labels Jun 2, 2020
@gunnsth
Copy link
Contributor Author

gunnsth commented Nov 24, 2020

This seems rather uncommon, have not run into files using this.

@anovik
Copy link

anovik commented Nov 29, 2024

Crypt filter has been implemented, see core/crypt.go.

@anovik anovik closed this as completed Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Package core encoding/other enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants