编码是隐匿在计算机软硬件背后的语言,是计算机的灵魂。
1.引言
数字签名可以用于认证使用者身份和文档信息。数字签名存储了签名者和文档被签名时的状态。本节将对PDF生成数字签名进行介绍。
2.预备知识
由于之前的博客已经对PDF的结构进行了介绍,这里不再赘述。
在PDF文件中,签名信息一般存储在签名字典(Signature Dictionary)中,详见下图。
3.数字签名结构
对于一个已签名的PDF文档,内部结构如下图:
在其签名字典中,ByteRange数组指示了文档中需要哈希加密的字节(开始和结束位置),详见下图:
对于Contents内部的Signature Value,即SignedData,结构如下:
SignedData::= SEQUENCE {
version Version,
digestAlgorithms DigestAlgorithmIdentifiers,
contentInfo ContentInfo,
certificates [0] IMPLICIT ExtendedCertificatesAndCertificates OPTIONAL,
crls [1] IMPLICIT CertificateRevocationLists OPTIONAL,
signerInfos SignerInfos
}
对于在SignedData中的SignerInfos,结构如下:
SignerInfo ::= SEQUENCE {
version Version,
issuerAndSerialNumber IssuerAndSerialNumber,
digestAlgorithm DigestAlgorithmIdentifier,
signedAttributes [0] IMPLICIT Attributes OPTIONAL,
digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier,
encryptedDigest EncryptedDigest,
unsignedAttributes [1] IMPLICIT Attributes OPTIONAL
}
一般,TimeStamp属性存储在签名的unsignedAttributes或signedAttributes中,常采用的是unsignedAttributes(如signature-time-stamp 属性),生成TimeStamp属性一般需要将特定数据发到时间戳服务器,具体发送什么数据根据TimeStamp属性选择:
4.数字签名流程
数字签名的流程如下:
5.总结
PDF内部数字签名的生成依据的主要还是PDF的相关文档,如RFC3161(www.rfc-editor.org/rfc/rfc3161,PDF格式的官方文档等。