Discuss this help topic in SecureBlackbox Forum

Sign document

To sign OpenOffice (Open Document Format, ODF) document using XML digital signature handler you need to

  1. create an instance of TElOpenOfficeSignatureHandler class and add it to the document using AddSignature() method of the document object
  2. specify what information should be signed by adding document parts or the whole document to sign. The whole document can be added using AddDocument() method of the handler. Document parts can be added using AddSignedEntry() method of the handler.
  3. configure signature-releated properties of the handler, such as XAdES info
  4. call Sign() method to sign, after that close the document to flush changes

C#:


void SignOpenOffice(string sourceFilename, TElX509Certificate certificate)
{
    using (TElOfficeDocument Document = new TElOfficeDocument())
    {
        Document.Open(sourceFilename);
        if ((Document.DocumentFormat != TSBOfficeDocumentFormat.OpenDocument) || !Document.Signable)
            throw new Exception("Cannot sign document using XML signature handler");

        TElOpenOfficeSignatureHandler ODFSigHandler = new TElOpenOfficeSignatureHandler();
        Document.AddSignature(ODFSigHandler, true);

        ODFSigHandler.AddDocument();
        ODFSigHandler.Sign(certificate);
    }
}
Delphi:

procedure SignOpenOffice(const SourceFilename : string; Certificate : TElX509Certificate);
var
  Document : TElOfficeDocument;
  ODFSigHandler : TElOpenOfficeSignatureHandler;
begin
  Document := TElOfficeDocument.Create(nil);
  try
    Document.Open(SourceFilename);
    if (Document.DocumentFormat <> dfOpenDocument) or not Document.Signable then
      raise Exception.Create('Cannot sign document using XML signature handler');

    ODFSigHandler := TElOpenOfficeSignatureHandler.Create(nil);
    Document.AddSignature(ODFSigHandler, True);

    ODFSigHandler.AddDocument();
    ODFSigHandler.Sign(Certificate);
  finally
    FreeAndNil(Document);
  end;
end;

How To articles about OpenOffice documents

Discuss this help topic in SecureBlackbox Forum