【发布时间】:2017-07-11 07:09:27
【问题描述】:
我有一个包含多个签名字段的 pdf。我正在使用 iTextSharp 来创建带有签名字段的 pdf,并且我正在尝试使用 CoSign SAPI 对每个签名字段进行签名。当我从调用的响应中附加签名对象时,签名无效。
下面是我使用的代码示例,用于从包含许多(签名字段)的 pdf 文档中对现有签名字段进行签名:
public void SignDocument(string filePath, string fieldName, string username, string password)
{
byte[] fileBuffer = File.ReadAllBytes(filePath);
DocumentType document = new DocumentType()
{
Item = new DocumentTypeBase64Data()
{
Value = fileBuffer,
MimeType = "application/pdf"
}
};
ClaimedIdentity claimedIdentity = new ClaimedIdentity()
{
Name = new NameIdentifierType()
{
Value = username
},
SupportingInfo = new CoSignAuthDataType()
{
LogonPassword = password
}
};
SAPISigFieldSettingsType sigFieldSettings = new SAPISigFieldSettingsType()
{
Invisible = true,
InvisibleSpecified = true,
X = 145,
XSpecified = true,
Y = 125,
YSpecified = true,
Width = 160,
WidthSpecified = true,
Height = 45,
HeightSpecified = true,
Page = 1,
PageSpecified = true,
AppearanceMask = 11,
AppearanceMaskSpecified = true,
TimeFormat = new TimeDateFormatType()
{
TimeFormat = "hh:mm:ss",
DateFormat = "dd/MM/yyyy",
ExtTimeFormat = ExtendedTimeFormatEnum.GMT,
ExtTimeFormatSpecified = true
}
};
SignRequest signRequest = new SignRequest()
{
InputDocuments = new RequestBaseTypeInputDocuments()
{
Items = new DocumentType[] { document }
},
OptionalInputs = new RequestBaseTypeOptionalInputs()
{
SignatureType = "http://arx.com/SAPIWS/DSS/1.0/signature-field-sign",
ClaimedIdentity = claimedIdentity,
SAPISigFieldSettings = sigFieldSettings,
ReturnPDFTailOnly = true,
ReturnPDFTailOnlySpecified = true,
SignatureFieldName = fieldName
}
};
DssSignResult response = _client.DssSign(signRequest);
if (response.Result.ResultMajor.Equals(SIGN_SUCCESS_RESULT_MAJOR))
{
byte[] signatureBuffer = ((DssSignResultSignatureObjectBase64Signature)response.SignatureObject.Item).Value;
using (var fileStream = new FileStream(filePath, FileMode.Append))
{
fileStream.Write(signatureBuffer, 0, signatureBuffer.Length);
}
}
else
{
throw new Exception(response.Result.ResultMessage.Value);
}
}
这是我要签名的文件。我正在尝试签署签名字段“sig2-9”,但签名无效,并显示消息“对此文档进行了更改,导致签名无效”。很抱歉没有发布签名文件,但证书所有者不想分享他的个人信息。
这是带有无效签名的签名文件。
这是我用另一个 CoSign api 调用签名的文件。此调用创建签名字段并使用与“签名文件”相同的证书对其进行签名。如您所见,此示例中的签名是有效的。在此示例中,我使用了“http://arx.com/SAPIWS/DSS/1.0/signature-field-create-sign”签名类型。
【问题讨论】:
-
我不认识代码(可能是因为它是 cosign 代码),但是如果您使用 iText 创建 PDF,为什么不使用 iText 签署 PDF?
-
@BrunoLowagie “你为什么不用 iText 签署 PDF” - 我认为问题是关于通过 DocuSign 签署的。有没有一种简单的方法可以将 DocuSign 集成到 iText 签名中? (实际上我还没有玩过 DocuSign,所以我不知道这会是多么复杂或容易......)
-
DocuSign 是 iText 的客户,因此这两种技术应该可以很好地协同工作,但我对 CoSign API 不熟悉。
-
@BrunoLowagie - 我不能使用 iTextSharp 来签署 pdf 文件,因为私钥存储在 CoSign 服务器上。我使用 pdf 文件在 CoSign 服务器上进行 Soap 调用,服务器返回文件的签名哈希。当我完成签名并打开文件时,签名无效。
-
好吧@mkl,假设 Kostas 是 CoSign/Docusign 的客户,解决此问题的最佳方法是联系 Docusign 的客户支持,并要求他们在 iText 提交支持票。跨度>
标签: itext digital-signature docusignapi cosign-api