公開鍵暗号による暗号化 PDF の仕様ではまった
PDF 生成プログラムで公開鍵暗号暗号化したPDFが Acrobat で開くとデジタルID がありませんというメッセージが出て開けないという状態でしばらくはまってました。
とりあえず解決したっぽいのだけど、なんだか腑に落ちないところがあるのでメモ。
原因は PDF に埋め込む権限情報の値の 1bit 目を 0 にしていたから。1 にしたらあっさり開けるようになりました。
追記2013/12/12ここから
2bit 目 1、1bit 目 0 でも開けました。
どうも下位 2bit が共に 0 の場合がだめのようです。
追記2013/12/12ここまで
PDF リファレンスの Errata に設定値の説明が載っています。*1
5 ページの下部から抜粋。
KEY | TYPE | VALUE |
---|---|---|
P | integer | (Required) A set of flags specifying which operations shall be permitted when the document is opened with user access. If bit 2 is set to 1, all other bits are ignored and all operations are permitted. If bit 2 is set to 0, permission for operations are based on the values of the remaining flags defined in Table 3.21a. |
Table 3.21a
Bit position | Meaning |
---|---|
2 | Permit change of encryption and enable all other permissions. |
3 | Print the document (possibly not at the highest quality level, depending on whether bit 12 is also set). |
4 | Modify the contents of the document by operations other than those controlled by bits 6, 9, and 11. |
5 | Copy or otherwise extract text and graphics from the document by operations other than that controlled by bit 10. |
6 | Add or modify text annotations, fill in interactive form fields, and, if bit 4 is also set, create or modify interactive form fields (including signature fields). |
9 | Fill in existing interactive form fields (including signature fields), even if bit 6 is clear. |
10 | Extract text and graphics (in support of accessibility to users with disabilities or for other purposes). |
11 | Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if bit 4 is clear. |
12 | Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this bit is clear (and bit 3 is set),printing is limited to a low-level representation of the appearance, possibly of degraded quality. |
こんな重要情報が Errata にしか書いてないのもどうかと思うけど、この記述からは 1bit 目を 1 にしないといけないようには読めないのですが。
なんか読み方間違ってる?
ちなみにパスワードによる暗号化の場合も権限情報を埋め込むのですが、そっちは下位 2bit が 0 固定という罠。
同じと思い込んでいたので気づくのに時間がかかりました。
*1:Errata の内容はリファレンス本編には載ってない