Skip to content

读取数字签名信息

将分别读取文档持有的数字签名,签名持有的签名者,签名者持有的数字证书中的部分信息。

所有可获取的信息详见 API Reference。

关键代码

objective-c
NSURL *url = [NSURL fileURLWithPath:@"file path"];

CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];

NSArray *signatures = [document signatures];
if (signatures.count > 0) {
  for (CPDFSignature *signature in signatures) {
      self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Name: %@\n", signature.name];
      self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Location: %@\n", signature.location];
      self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Reason: %@\n", signature.reason];
      self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Date: %@\n", signature.date];
      self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Subject: %@\n", signature.subFilter];
	}
}

签名、签名者、证书的关系

数字签名是通过使用签名者的私钥对文档进行加密生成的,然后使用签名者的证书中的公钥来验证签名的有效性。签名、签名者、数字证书一起构成了PDF文档中数字签名的关键部分。

一般情况下,一个签名对应一个签名者。但在某些情况下,一个数字签名可以包含多个签名者,每个签名者可以拥有自己的证书链。这种多签名者的机制在某些应用场景下非常有用,因为它允许多个实体对同一文档进行数字签名,每个实体可以使用自己的证书和私钥。