Discuss this help topic in SecureBlackbox Forum
Sign document with XML signature handler
To sign a binary document using XML signature handler you need to
C#:
void SignBinaryXML(string sourceFilename, TElX509Certificate certificate)
{
using (TElOfficeDocument Document = new TElOfficeDocument())
{
Document.Open(sourceFilename);
if ((Document.DocumentFormat != TSBOfficeDocumentFormat.Binary) || !Document.Signable)
throw new Exception("Cannot sign document using Binary XML signature handler");
TElOfficeBinaryXMLSignatureHandler BinXMLSigHandler = new TElOfficeBinaryXMLSignatureHandler();
Document.AddSignature(BinXMLSigHandler, true);
BinXMLSigHandler.SignatureInfoV1.Included = true;
BinXMLSigHandler.SignatureInfoV1.SignatureComments = "Comments";
BinXMLSigHandler.Sign(certificate);
}
}
Delphi:
procedure SignBinaryXML(const SourceFilename : string; Certificate : TElX509Certificate);
var
Document : TElOfficeDocument;
BinXMLSigHandler : TElOfficeBinaryXMLSignatureHandler;
begin
Document := TElOfficeDocument.Create(nil);
try
Document.Open(SourceFilename);
if (Document.DocumentFormat <> dfBinary) or (not Document.Signable) then
raise Exception.Create('Cannot sign document using Binary XML signature handler');
BinXMLSigHandler := TElOfficeBinaryXMLSignatureHandler.Create(nil);
Document.AddSignature(BinXMLSigHandler, True);
BinXMLSigHandler.SignatureInfoV1.Included := true;
BinXMLSigHandler.SignatureInfoV1.SignatureComments := 'Comments';
BinXMLSigHandler.Sign(Certificate);
finally
FreeAndNil(Document);
end;
end;