Aspose::Words::DigitalSignatures::DigitalSignatureUtil Class Reference

Detailed Description

Provides methods for signing document.

Since digital signature works with file content rather than Document Object Model these methods are put into a separate class.

Supported formats are Doc and Docx.

Examples

Shows how to load signatures from a digitally signed document.

// There are two ways of loading a signed document's collection of digital signatures using the DigitalSignatureUtil class.
// 1 - Load from a document from a local file system filename:
SharedPtr<DigitalSignatureCollection> digitalSignatures = DigitalSignatureUtil::LoadSignatures(MyDir + u"Digitally signed.docx");
// If this collection is nonempty, then we can verify that the document is digitally signed.
ASSERT_EQ(1, digitalSignatures->get_Count());
// 2 - Load from a document from a FileStream:
{
SharedPtr<System::IO::Stream> stream = MakeObject<System::IO::FileStream>(MyDir + u"Digitally signed.docx", System::IO::FileMode::Open);
digitalSignatures = DigitalSignatureUtil::LoadSignatures(stream);
ASSERT_EQ(1, digitalSignatures->get_Count());
}

Shows how to remove digital signatures from a digitally signed document.

// There are two ways of using the DigitalSignatureUtil class to remove digital signatures
// from a signed document by saving an unsigned copy of it somewhere else in the local file system.
// 1 - Determine the locations of both the signed document and the unsigned copy by filename strings:
DigitalSignatureUtil::RemoveAllSignatures(MyDir + u"Digitally signed.docx", ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromString.docx");
// 2 - Determine the locations of both the signed document and the unsigned copy by file streams:
{
SharedPtr<System::IO::Stream> streamIn = MakeObject<System::IO::FileStream>(MyDir + u"Digitally signed.docx", System::IO::FileMode::Open);
{
SharedPtr<System::IO::Stream> streamOut =
MakeObject<System::IO::FileStream>(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromStream.docx", System::IO::FileMode::Create);
}
}
// Verify that both our output documents have no digital signatures.
ASSERT_EQ(0, DigitalSignatureUtil::LoadSignatures(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromString.docx")->get_Count());
ASSERT_EQ(0, DigitalSignatureUtil::LoadSignatures(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromStream.docx")->get_Count());

#include <Aspose.Words.Cpp/DigitalSignatures/DigitalSignatureUtil.h>

Public Member Functions

 DigitalSignatureUtil ()=delete
 

Static Public Member Functions

static SharedPtr< DigitalSignatureCollectionLoadSignatures (const SharedPtr< Stream > &stream)
 Loads digital signatures from document using stream. More...
 
static SharedPtr< DigitalSignatureCollectionLoadSignatures (const String &fileName)
 Loads digital signatures from document. More...
 
template<typename CharType , typename Traits >
static SharedPtr< DigitalSignatureCollectionLoadSignatures (std::basic_istream< CharType, Traits > &stream)
 
static void RemoveAllSignatures (const SharedPtr< Stream > &srcStream, const SharedPtr< Stream > &dstStream)
 Removes all digital signatures from document in source stream and writes unsigned document to destination stream. Output will be written to the start of stream and stream size will be updated with content length. More...
 
static void RemoveAllSignatures (const String &srcFileName, const String &dstFileName)
 Removes all digital signatures from source file and writes unsigned file to destination file. More...
 
template<typename CharType , typename Traits >
static void RemoveAllSignatures (std::basic_istream< CharType, Traits > &srcStream, std::basic_ostream< CharType, Traits > &dstStream)
 
static void Sign (const SharedPtr< Stream > &srcStream, const SharedPtr< Stream > &dstStream, const SharedPtr< CertificateHolder > &certHolder)
 Signs source document using given CertificateHolder with digital signature and writes signed document to destination stream. Document should be either Doc or Docx.Output will be written to the start of stream and stream size will be updated with content length. More...
 
static void Sign (const SharedPtr< Stream > &srcStream, const SharedPtr< Stream > &dstStream, const SharedPtr< CertificateHolder > &certHolder, const SharedPtr< SignOptions > &signOptions)
 Signs source document using given CertificateHolder and SignOptions with digital signature and writes signed document to destination stream. Document should be either Doc or Docx.Output will be written to the start of stream and stream size will be updated with content length. More...
 
static void Sign (const String &srcFileName, const String &dstFileName, const SharedPtr< CertificateHolder > &certHolder)
 Signs source document using given CertificateHolder with digital signature and writes signed document to destination file. Document should be either Doc or Docx. More...
 
static void Sign (const String &srcFileName, const String &dstFileName, const SharedPtr< CertificateHolder > &certHolder, const SharedPtr< SignOptions > &signOptions)
 Signs source document using given CertificateHolder and SignOptions with digital signature and writes signed document to destination file. Document should be either Doc or Docx. More...
 
template<typename CharType , typename Traits >
static void Sign (std::basic_istream< CharType, Traits > &srcStream, std::basic_ostream< CharType, Traits > &dstStream, SharedPtr< CertificateHolder > certHolder)
 
template<typename CharType , typename Traits >
static void Sign (std::basic_istream< CharType, Traits > &srcStream, std::basic_ostream< CharType, Traits > &dstStream, SharedPtr< CertificateHolder > certHolder, SharedPtr< SignOptions > signOptions)
 

Constructor & Destructor Documentation

◆ DigitalSignatureUtil()

Aspose::Words::DigitalSignatures::DigitalSignatureUtil::DigitalSignatureUtil ( )
delete

Member Function Documentation

◆ LoadSignatures() [1/3]

static System::SharedPtr<Aspose::Words::DigitalSignatures::DigitalSignatureCollection> Aspose::Words::DigitalSignatures::DigitalSignatureUtil::LoadSignatures ( const System::SharedPtr< System::IO::Stream > &  stream)
static

Loads digital signatures from document using stream.

Parameters
streamStream with the document.
Returns
Collection of digital signatures. Returns empty collection if file is not signed.
Examples

Shows how to load signatures from a digitally signed document.

// There are two ways of loading a signed document's collection of digital signatures using the DigitalSignatureUtil class.
// 1 - Load from a document from a local file system filename:
SharedPtr<DigitalSignatureCollection> digitalSignatures = DigitalSignatureUtil::LoadSignatures(MyDir + u"Digitally signed.docx");
// If this collection is nonempty, then we can verify that the document is digitally signed.
ASSERT_EQ(1, digitalSignatures->get_Count());
// 2 - Load from a document from a FileStream:
{
SharedPtr<System::IO::Stream> stream = MakeObject<System::IO::FileStream>(MyDir + u"Digitally signed.docx", System::IO::FileMode::Open);
digitalSignatures = DigitalSignatureUtil::LoadSignatures(stream);
ASSERT_EQ(1, digitalSignatures->get_Count());
}

◆ LoadSignatures() [2/3]

static System::SharedPtr<Aspose::Words::DigitalSignatures::DigitalSignatureCollection> Aspose::Words::DigitalSignatures::DigitalSignatureUtil::LoadSignatures ( const System::String fileName)
static

Loads digital signatures from document.

Parameters
fileNamePath to the document.
Returns
Collection of digital signatures. Returns empty collection if file is not signed.
Examples

Shows how to load signatures from a digitally signed document.

// There are two ways of loading a signed document's collection of digital signatures using the DigitalSignatureUtil class.
// 1 - Load from a document from a local file system filename:
SharedPtr<DigitalSignatureCollection> digitalSignatures = DigitalSignatureUtil::LoadSignatures(MyDir + u"Digitally signed.docx");
// If this collection is nonempty, then we can verify that the document is digitally signed.
ASSERT_EQ(1, digitalSignatures->get_Count());
// 2 - Load from a document from a FileStream:
{
SharedPtr<System::IO::Stream> stream = MakeObject<System::IO::FileStream>(MyDir + u"Digitally signed.docx", System::IO::FileMode::Open);
digitalSignatures = DigitalSignatureUtil::LoadSignatures(stream);
ASSERT_EQ(1, digitalSignatures->get_Count());
}

Shows how to remove digital signatures from a digitally signed document.

// There are two ways of using the DigitalSignatureUtil class to remove digital signatures
// from a signed document by saving an unsigned copy of it somewhere else in the local file system.
// 1 - Determine the locations of both the signed document and the unsigned copy by filename strings:
DigitalSignatureUtil::RemoveAllSignatures(MyDir + u"Digitally signed.docx", ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromString.docx");
// 2 - Determine the locations of both the signed document and the unsigned copy by file streams:
{
SharedPtr<System::IO::Stream> streamIn = MakeObject<System::IO::FileStream>(MyDir + u"Digitally signed.docx", System::IO::FileMode::Open);
{
SharedPtr<System::IO::Stream> streamOut =
MakeObject<System::IO::FileStream>(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromStream.docx", System::IO::FileMode::Create);
}
}
// Verify that both our output documents have no digital signatures.
ASSERT_EQ(0, DigitalSignatureUtil::LoadSignatures(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromString.docx")->get_Count());
ASSERT_EQ(0, DigitalSignatureUtil::LoadSignatures(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromStream.docx")->get_Count());

◆ LoadSignatures() [3/3]

template<typename CharType , typename Traits >
static System::SharedPtr<Aspose::Words::DigitalSignatures::DigitalSignatureCollection> Aspose::Words::DigitalSignatures::DigitalSignatureUtil::LoadSignatures ( std::basic_istream< CharType, Traits > &  stream)
inlinestatic

◆ RemoveAllSignatures() [1/3]

static void Aspose::Words::DigitalSignatures::DigitalSignatureUtil::RemoveAllSignatures ( const System::SharedPtr< System::IO::Stream > &  srcStream,
const System::SharedPtr< System::IO::Stream > &  dstStream 
)
static

Removes all digital signatures from document in source stream and writes unsigned document to destination stream. Output will be written to the start of stream and stream size will be updated with content length.

Examples

Shows how to remove digital signatures from a digitally signed document.

// There are two ways of using the DigitalSignatureUtil class to remove digital signatures
// from a signed document by saving an unsigned copy of it somewhere else in the local file system.
// 1 - Determine the locations of both the signed document and the unsigned copy by filename strings:
DigitalSignatureUtil::RemoveAllSignatures(MyDir + u"Digitally signed.docx", ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromString.docx");
// 2 - Determine the locations of both the signed document and the unsigned copy by file streams:
{
SharedPtr<System::IO::Stream> streamIn = MakeObject<System::IO::FileStream>(MyDir + u"Digitally signed.docx", System::IO::FileMode::Open);
{
SharedPtr<System::IO::Stream> streamOut =
MakeObject<System::IO::FileStream>(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromStream.docx", System::IO::FileMode::Create);
}
}
// Verify that both our output documents have no digital signatures.
ASSERT_EQ(0, DigitalSignatureUtil::LoadSignatures(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromString.docx")->get_Count());
ASSERT_EQ(0, DigitalSignatureUtil::LoadSignatures(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromStream.docx")->get_Count());

◆ RemoveAllSignatures() [2/3]

static void Aspose::Words::DigitalSignatures::DigitalSignatureUtil::RemoveAllSignatures ( const System::String srcFileName,
const System::String dstFileName 
)
static

Removes all digital signatures from source file and writes unsigned file to destination file.

Examples

Shows how to remove digital signatures from a digitally signed document.

// There are two ways of using the DigitalSignatureUtil class to remove digital signatures
// from a signed document by saving an unsigned copy of it somewhere else in the local file system.
// 1 - Determine the locations of both the signed document and the unsigned copy by filename strings:
DigitalSignatureUtil::RemoveAllSignatures(MyDir + u"Digitally signed.docx", ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromString.docx");
// 2 - Determine the locations of both the signed document and the unsigned copy by file streams:
{
SharedPtr<System::IO::Stream> streamIn = MakeObject<System::IO::FileStream>(MyDir + u"Digitally signed.docx", System::IO::FileMode::Open);
{
SharedPtr<System::IO::Stream> streamOut =
MakeObject<System::IO::FileStream>(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromStream.docx", System::IO::FileMode::Create);
}
}
// Verify that both our output documents have no digital signatures.
ASSERT_EQ(0, DigitalSignatureUtil::LoadSignatures(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromString.docx")->get_Count());
ASSERT_EQ(0, DigitalSignatureUtil::LoadSignatures(ArtifactsDir + u"DigitalSignatureUtil.LoadAndRemove.FromStream.docx")->get_Count());

◆ RemoveAllSignatures() [3/3]

template<typename CharType , typename Traits >
static void Aspose::Words::DigitalSignatures::DigitalSignatureUtil::RemoveAllSignatures ( std::basic_istream< CharType, Traits > &  srcStream,
std::basic_ostream< CharType, Traits > &  dstStream 
)
inlinestatic

◆ Sign() [1/6]

static void Aspose::Words::DigitalSignatures::DigitalSignatureUtil::Sign ( const System::SharedPtr< System::IO::Stream > &  srcStream,
const System::SharedPtr< System::IO::Stream > &  dstStream,
const System::SharedPtr< Aspose::Words::DigitalSignatures::CertificateHolder > &  certHolder 
)
static

Signs source document using given CertificateHolder with digital signature and writes signed document to destination stream. Document should be either Doc or Docx.Output will be written to the start of stream and stream size will be updated with content length.

Parameters
srcStreamThe stream which contains the document to sign.
dstStreamThe stream that signed document will be written to.
certHolderCertificateHolder object with certificate that used to sign file. The certificate in holder MUST contain private keys.
Examples

Shows how to sign documents with X.509 certificates.

// Verify that a document is not signed.
ASSERT_FALSE(FileFormatUtil::DetectFileFormat(MyDir + u"Document.docx")->get_HasDigitalSignature());
// Create a CertificateHolder object from a PKCS12 file, which we will use to sign the document.
SharedPtr<CertificateHolder> certificateHolder = CertificateHolder::Create(MyDir + u"morzal.pfx", u"aw", nullptr);
// There are two ways of saving a signed copy of a document to the local file system:
// 1 - Designate a document by a local system filename and save a signed copy at a location specified by another filename.
auto signOptions = MakeObject<SignOptions>();
signOptions->set_SignTime(System::DateTime::get_Now());
DigitalSignatureUtil::Sign(MyDir + u"Document.docx", ArtifactsDir + u"Document.DigitalSignature.docx", certificateHolder, signOptions);
ASSERT_TRUE(FileFormatUtil::DetectFileFormat(ArtifactsDir + u"Document.DigitalSignature.docx")->get_HasDigitalSignature());
// 2 - Take a document from a stream and save a signed copy to another stream.
{
auto inDoc = MakeObject<System::IO::FileStream>(MyDir + u"Document.docx", System::IO::FileMode::Open);
{
auto outDoc = MakeObject<System::IO::FileStream>(ArtifactsDir + u"Document.DigitalSignature.docx", System::IO::FileMode::Create);
DigitalSignatureUtil::Sign(inDoc, outDoc, certificateHolder);
}
}
ASSERT_TRUE(FileFormatUtil::DetectFileFormat(ArtifactsDir + u"Document.DigitalSignature.docx")->get_HasDigitalSignature());
// Please verify that all of the document's digital signatures are valid and check their details.
auto signedDoc = MakeObject<Document>(ArtifactsDir + u"Document.DigitalSignature.docx");
SharedPtr<DigitalSignatureCollection> digitalSignatureCollection = signedDoc->get_DigitalSignatures();
ASSERT_TRUE(digitalSignatureCollection->get_IsValid());
ASSERT_EQ(1, digitalSignatureCollection->get_Count());
ASSERT_EQ(DigitalSignatureType::XmlDsig, digitalSignatureCollection->idx_get(0)->get_SignatureType());
ASSERT_EQ(u"CN=Morzal.Me", signedDoc->get_DigitalSignatures()->idx_get(0)->get_IssuerName());
ASSERT_EQ(u"CN=Morzal.Me", signedDoc->get_DigitalSignatures()->idx_get(0)->get_SubjectName());

◆ Sign() [2/6]

static void Aspose::Words::DigitalSignatures::DigitalSignatureUtil::Sign ( const System::SharedPtr< System::IO::Stream > &  srcStream,
const System::SharedPtr< System::IO::Stream > &  dstStream,
const System::SharedPtr< Aspose::Words::DigitalSignatures::CertificateHolder > &  certHolder,
const System::SharedPtr< Aspose::Words::DigitalSignatures::SignOptions > &  signOptions 
)
static

Signs source document using given CertificateHolder and SignOptions with digital signature and writes signed document to destination stream. Document should be either Doc or Docx.Output will be written to the start of stream and stream size will be updated with content length.

Parameters
srcStreamThe stream which contains the document to sign.
dstStreamThe stream that signed document will be written to.
certHolderCertificateHolder object with certificate that used to sign file. The certificate in holder MUST contain private keys.
signOptionsSignOptions object with various signing options.
Examples

Shows how to digitally sign documents.

// Create an X.509 certificate from a PKCS#12 store, which should contain a private key.
SharedPtr<CertificateHolder> certificateHolder = CertificateHolder::Create(MyDir + u"morzal.pfx", u"aw");
// Create a comment and date which will be applied with our new digital signature.
auto signOptions = MakeObject<SignOptions>();
signOptions->set_Comments(u"My comment");
signOptions->set_SignTime(System::DateTime::get_Now());
// Take an unsigned document from the local file system via a file stream,
// then create a signed copy of it determined by the filename of the output file stream.
{
SharedPtr<System::IO::Stream> streamIn = MakeObject<System::IO::FileStream>(MyDir + u"Document.docx", System::IO::FileMode::Open);
{
SharedPtr<System::IO::Stream> streamOut =
MakeObject<System::IO::FileStream>(ArtifactsDir + u"DigitalSignatureUtil.SignDocument.docx", System::IO::FileMode::OpenOrCreate);
DigitalSignatureUtil::Sign(streamIn, streamOut, certificateHolder, signOptions);
}
}

◆ Sign() [3/6]

static void Aspose::Words::DigitalSignatures::DigitalSignatureUtil::Sign ( const System::String srcFileName,
const System::String dstFileName,
const System::SharedPtr< Aspose::Words::DigitalSignatures::CertificateHolder > &  certHolder 
)
static

Signs source document using given CertificateHolder with digital signature and writes signed document to destination file. Document should be either Doc or Docx.

Parameters
srcFileNameThe file name of the document to sign.
dstFileNameThe file name of the signed document output.
certHolderCertificateHolder object with certificate that used to sign file. The certificate in holder MUST contain private keys.
Examples

Shows how to sign documents with X.509 certificates.

// Verify that a document is not signed.
ASSERT_FALSE(FileFormatUtil::DetectFileFormat(MyDir + u"Document.docx")->get_HasDigitalSignature());
// Create a CertificateHolder object from a PKCS12 file, which we will use to sign the document.
SharedPtr<CertificateHolder> certificateHolder = CertificateHolder::Create(MyDir + u"morzal.pfx", u"aw", nullptr);
// There are two ways of saving a signed copy of a document to the local file system:
// 1 - Designate a document by a local system filename and save a signed copy at a location specified by another filename.
auto signOptions = MakeObject<SignOptions>();
signOptions->set_SignTime(System::DateTime::get_Now());
DigitalSignatureUtil::Sign(MyDir + u"Document.docx", ArtifactsDir + u"Document.DigitalSignature.docx", certificateHolder, signOptions);
ASSERT_TRUE(FileFormatUtil::DetectFileFormat(ArtifactsDir + u"Document.DigitalSignature.docx")->get_HasDigitalSignature());
// 2 - Take a document from a stream and save a signed copy to another stream.
{
auto inDoc = MakeObject<System::IO::FileStream>(MyDir + u"Document.docx", System::IO::FileMode::Open);
{
auto outDoc = MakeObject<System::IO::FileStream>(ArtifactsDir + u"Document.DigitalSignature.docx", System::IO::FileMode::Create);
DigitalSignatureUtil::Sign(inDoc, outDoc, certificateHolder);
}
}
ASSERT_TRUE(FileFormatUtil::DetectFileFormat(ArtifactsDir + u"Document.DigitalSignature.docx")->get_HasDigitalSignature());
// Please verify that all of the document's digital signatures are valid and check their details.
auto signedDoc = MakeObject<Document>(ArtifactsDir + u"Document.DigitalSignature.docx");
SharedPtr<DigitalSignatureCollection> digitalSignatureCollection = signedDoc->get_DigitalSignatures();
ASSERT_TRUE(digitalSignatureCollection->get_IsValid());
ASSERT_EQ(1, digitalSignatureCollection->get_Count());
ASSERT_EQ(DigitalSignatureType::XmlDsig, digitalSignatureCollection->idx_get(0)->get_SignatureType());
ASSERT_EQ(u"CN=Morzal.Me", signedDoc->get_DigitalSignatures()->idx_get(0)->get_IssuerName());
ASSERT_EQ(u"CN=Morzal.Me", signedDoc->get_DigitalSignatures()->idx_get(0)->get_SubjectName());

◆ Sign() [4/6]

static void Aspose::Words::DigitalSignatures::DigitalSignatureUtil::Sign ( const System::String srcFileName,
const System::String dstFileName,
const System::SharedPtr< Aspose::Words::DigitalSignatures::CertificateHolder > &  certHolder,
const System::SharedPtr< Aspose::Words::DigitalSignatures::SignOptions > &  signOptions 
)
static

Signs source document using given CertificateHolder and SignOptions with digital signature and writes signed document to destination file. Document should be either Doc or Docx.

Parameters
srcFileNameThe file name of the document to sign.
dstFileNameThe file name of the signed document output.
certHolderCertificateHolder object with certificate that used to sign file. The certificate in holder MUST contain private keys.
signOptionsSignOptions object with various signing options.
Examples

Shows how to add a signature line to a document, and then sign it using a digital certificate.

static void Sign()
{
String signeeName = u"Ron Williams";
String srcDocumentPath = MyDir + u"Document.docx";
String dstDocumentPath = ArtifactsDir + u"SignDocumentCustom.Sign.docx";
String certificatePath = MyDir + u"morzal.pfx";
String certificatePassword = u"aw";
CreateSignees();
auto signeeInfo = mSignees->Find(System::Predicate<SharedPtr<Signee>>([&](SharedPtr<Signee> c) { return c->get_Name() == signeeName; }));
if (signeeInfo != nullptr)
{
SignDocument(srcDocumentPath, dstDocumentPath, signeeInfo, certificatePath, certificatePassword);
}
else
{
FAIL() << "Signee does not exist.";
}
}
class Signee : public System::Object
{
public:
System::Guid get_PersonId()
{
return pr_PersonId;
}
void set_PersonId(System::Guid value)
{
pr_PersonId = value;
}
String get_Name()
{
return pr_Name;
}
void set_Name(String value)
{
pr_Name = value;
}
String get_Position()
{
return pr_Position;
}
void set_Position(String value)
{
pr_Position = value;
}
ArrayPtr<uint8_t> get_Image()
{
return pr_Image;
}
void set_Image(ArrayPtr<uint8_t> value)
{
pr_Image = value;
}
Signee(System::Guid guid, String name, String position, ArrayPtr<uint8_t> image)
{
set_PersonId(guid);
set_Name(name);
set_Position(position);
set_Image(image);
}
private:
System::Guid pr_PersonId;
String pr_Name;
String pr_Position;
ArrayPtr<uint8_t> pr_Image;
};
static void SignDocument(String srcDocumentPath, String dstDocumentPath, SharedPtr<ExSignDocumentCustom::Signee> signeeInfo, String certificatePath,
String certificatePassword)
{
auto document = MakeObject<Document>(srcDocumentPath);
auto builder = MakeObject<DocumentBuilder>(document);
// Configure and insert a signature line, an object in the document that will display a signature that we sign it with.
auto signatureLineOptions = MakeObject<SignatureLineOptions>();
signatureLineOptions->set_Signer(signeeInfo->get_Name());
signatureLineOptions->set_SignerTitle(signeeInfo->get_Position());
SharedPtr<SignatureLine> signatureLine = builder->InsertSignatureLine(signatureLineOptions)->get_SignatureLine();
signatureLine->set_Id(signeeInfo->get_PersonId());
// First, we will save an unsigned version of our document.
builder->get_Document()->Save(dstDocumentPath);
SharedPtr<CertificateHolder> certificateHolder = CertificateHolder::Create(certificatePath, certificatePassword);
auto signOptions = MakeObject<SignOptions>();
signOptions->set_SignatureLineId(signeeInfo->get_PersonId());
signOptions->set_SignatureLineImage(signeeInfo->get_Image());
// Overwrite the unsigned document we saved above with a version signed using the certificate.
DigitalSignatureUtil::Sign(dstDocumentPath, dstDocumentPath, certificateHolder, signOptions);
}
static ArrayPtr<uint8_t> ImageToByteArray(SharedPtr<System::Drawing::Image> imageIn)
{
{
auto ms = MakeObject<System::IO::MemoryStream>();
return ms->ToArray();
}
}
static void CreateSignees()
{
mSignees = MakeObject<System::Collections::Generic::List<SharedPtr<ExSignDocumentCustom::Signee>>>();
mSignees->Add(MakeObject<ExSignDocumentCustom::Signee>(System::Guid::NewGuid(), u"Ron Williams", u"Chief Executive Officer",
ImageToByteArray(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"))));
mSignees->Add(MakeObject<ExSignDocumentCustom::Signee>(System::Guid::NewGuid(), u"Stephen Morse", u"Head of Compliance",
ImageToByteArray(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"))));
}
static SharedPtr<System::Collections::Generic::List<SharedPtr<ExSignDocumentCustom::Signee>>> mSignees;

◆ Sign() [5/6]

template<typename CharType , typename Traits >
static void Aspose::Words::DigitalSignatures::DigitalSignatureUtil::Sign ( std::basic_istream< CharType, Traits > &  srcStream,
std::basic_ostream< CharType, Traits > &  dstStream,
System::SharedPtr< Aspose::Words::DigitalSignatures::CertificateHolder certHolder 
)
inlinestatic

◆ Sign() [6/6]

template<typename CharType , typename Traits >
static void Aspose::Words::DigitalSignatures::DigitalSignatureUtil::Sign ( std::basic_istream< CharType, Traits > &  srcStream,
std::basic_ostream< CharType, Traits > &  dstStream,
System::SharedPtr< Aspose::Words::DigitalSignatures::CertificateHolder certHolder,
System::SharedPtr< Aspose::Words::DigitalSignatures::SignOptions signOptions 
)
inlinestatic