Aspose::Words::Saving::PdfDigitalSignatureDetails Class Reference

Detailed Description

Contains details for signing a PDF document with a digital signature.

At the moment digitally signing PDF documents is only available on .NET 2.0 or higher.

To digitally sign a PDF document when it is created by Aspose.Words, set the DigitalSignatureDetails property to a valid PdfDigitalSignatureDetails object and then save the document in the PDF format passing the PdfSaveOptions as a parameter into the Save() method.

Aspose.Words creates a PKCS#7 signature over the whole PDF document and uses the "Adobe.PPKMS" filter and "adbe.pkcs7.sha1" subfilter when creating a digital signature.

See also
Aspose::Words::Saving::PdfSaveOptions::get_DigitalSignatureDetails
Examples

Shows how to sign a generated PDF document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Contents of signed PDF.");
SharedPtr<CertificateHolder> certificateHolder = CertificateHolder::Create(MyDir + u"morzal.pfx", u"aw");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
auto options = MakeObject<PdfSaveOptions>();
// Configure the "DigitalSignatureDetails" object of the "SaveOptions" object to
// digitally sign the document as we render it with the "Save" method.
options->set_DigitalSignatureDetails(MakeObject<PdfDigitalSignatureDetails>(certificateHolder, u"Test Signing", u"My Office", signingTime));
options->get_DigitalSignatureDetails()->set_HashAlgorithm(PdfDigitalSignatureHashAlgorithm::Sha256);
ASSERT_EQ(u"Test Signing", options->get_DigitalSignatureDetails()->get_Reason());
ASSERT_EQ(u"My Office", options->get_DigitalSignatureDetails()->get_Location());
ASSERT_EQ(signingTime.ToUniversalTime(), options->get_DigitalSignatureDetails()->get_SignatureDate().ToUniversalTime());
doc->Save(ArtifactsDir + u"PdfSaveOptions.PdfDigitalSignature.pdf", options);

#include <Aspose.Words.Cpp/Saving/PdfDigitalSignatureDetails.h>

+ Inheritance diagram for Aspose::Words::Saving::PdfDigitalSignatureDetails:

Public Member Functions

 PdfDigitalSignatureDetails ()
 Initializes an instance of this class. More...
 
 PdfDigitalSignatureDetails (const SharedPtr< CertificateHolder > &certificateHolder, const String &reason, const String &location, DateTime signatureDate)
 Initializes an instance of this class. More...
 
SharedPtr< CertificateHolderget_CertificateHolder () const
 Returns the certificate holder object that contains the certificate was used to sign the document. More...
 
PdfDigitalSignatureHashAlgorithm get_HashAlgorithm () const
 Gets or sets the hash algorithm. More...
 
String get_Location () const
 Gets or sets the location of the signing. More...
 
String get_Reason () const
 Gets or sets the reason for the signing. More...
 
DateTime get_SignatureDate () const
 Gets or sets the date of the signing. More...
 
SharedPtr< PdfDigitalSignatureTimestampSettingsget_TimestampSettings () const
 Gets or sets the digital signature timestamp settings. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_CertificateHolder (const SharedPtr< CertificateHolder > &value)
 Returns the certificate holder object that contains the certificate was used to sign the document. More...
 
void set_HashAlgorithm (PdfDigitalSignatureHashAlgorithm value)
 Setter for get_HashAlgorithm. More...
 
void set_Location (const String &value)
 Setter for get_Location. More...
 
void set_Reason (const String &value)
 Setter for get_Reason. More...
 
void set_SignatureDate (DateTime value)
 Setter for get_SignatureDate. More...
 
void set_TimestampSettings (const SharedPtr< PdfDigitalSignatureTimestampSettings > &value)
 Setter for get_TimestampSettings. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Constructor & Destructor Documentation

◆ PdfDigitalSignatureDetails() [1/2]

Aspose::Words::Saving::PdfDigitalSignatureDetails::PdfDigitalSignatureDetails ( )

Initializes an instance of this class.

◆ PdfDigitalSignatureDetails() [2/2]

Aspose::Words::Saving::PdfDigitalSignatureDetails::PdfDigitalSignatureDetails ( const System::SharedPtr< Aspose::Words::DigitalSignatures::CertificateHolder > &  certificateHolder,
const System::String reason,
const System::String location,
System::DateTime  signatureDate 
)

Initializes an instance of this class.

Parameters
certificateHolderA certificate holder which contains the certificate itself.
reasonThe reason for signing.
locationThe location of signing.
signatureDateThe date and time of signing.
Examples

Shows how to sign a generated PDF document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Contents of signed PDF.");
SharedPtr<CertificateHolder> certificateHolder = CertificateHolder::Create(MyDir + u"morzal.pfx", u"aw");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
auto options = MakeObject<PdfSaveOptions>();
// Configure the "DigitalSignatureDetails" object of the "SaveOptions" object to
// digitally sign the document as we render it with the "Save" method.
options->set_DigitalSignatureDetails(MakeObject<PdfDigitalSignatureDetails>(certificateHolder, u"Test Signing", u"My Office", signingTime));
options->get_DigitalSignatureDetails()->set_HashAlgorithm(PdfDigitalSignatureHashAlgorithm::Sha256);
ASSERT_EQ(u"Test Signing", options->get_DigitalSignatureDetails()->get_Reason());
ASSERT_EQ(u"My Office", options->get_DigitalSignatureDetails()->get_Location());
ASSERT_EQ(signingTime.ToUniversalTime(), options->get_DigitalSignatureDetails()->get_SignatureDate().ToUniversalTime());
doc->Save(ArtifactsDir + u"PdfSaveOptions.PdfDigitalSignature.pdf", options);

Member Function Documentation

◆ get_CertificateHolder()

System::SharedPtr<Aspose::Words::DigitalSignatures::CertificateHolder> Aspose::Words::Saving::PdfDigitalSignatureDetails::get_CertificateHolder ( ) const

Returns the certificate holder object that contains the certificate was used to sign the document.

◆ get_HashAlgorithm()

Aspose::Words::Saving::PdfDigitalSignatureHashAlgorithm Aspose::Words::Saving::PdfDigitalSignatureDetails::get_HashAlgorithm ( ) const

Gets or sets the hash algorithm.

Examples

Shows how to sign a generated PDF document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Contents of signed PDF.");
SharedPtr<CertificateHolder> certificateHolder = CertificateHolder::Create(MyDir + u"morzal.pfx", u"aw");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
auto options = MakeObject<PdfSaveOptions>();
// Configure the "DigitalSignatureDetails" object of the "SaveOptions" object to
// digitally sign the document as we render it with the "Save" method.
options->set_DigitalSignatureDetails(MakeObject<PdfDigitalSignatureDetails>(certificateHolder, u"Test Signing", u"My Office", signingTime));
options->get_DigitalSignatureDetails()->set_HashAlgorithm(PdfDigitalSignatureHashAlgorithm::Sha256);
ASSERT_EQ(u"Test Signing", options->get_DigitalSignatureDetails()->get_Reason());
ASSERT_EQ(u"My Office", options->get_DigitalSignatureDetails()->get_Location());
ASSERT_EQ(signingTime.ToUniversalTime(), options->get_DigitalSignatureDetails()->get_SignatureDate().ToUniversalTime());
doc->Save(ArtifactsDir + u"PdfSaveOptions.PdfDigitalSignature.pdf", options);

◆ get_Location()

System::String Aspose::Words::Saving::PdfDigitalSignatureDetails::get_Location ( ) const

Gets or sets the location of the signing.

Examples

Shows how to sign a generated PDF document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Contents of signed PDF.");
SharedPtr<CertificateHolder> certificateHolder = CertificateHolder::Create(MyDir + u"morzal.pfx", u"aw");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
auto options = MakeObject<PdfSaveOptions>();
// Configure the "DigitalSignatureDetails" object of the "SaveOptions" object to
// digitally sign the document as we render it with the "Save" method.
options->set_DigitalSignatureDetails(MakeObject<PdfDigitalSignatureDetails>(certificateHolder, u"Test Signing", u"My Office", signingTime));
options->get_DigitalSignatureDetails()->set_HashAlgorithm(PdfDigitalSignatureHashAlgorithm::Sha256);
ASSERT_EQ(u"Test Signing", options->get_DigitalSignatureDetails()->get_Reason());
ASSERT_EQ(u"My Office", options->get_DigitalSignatureDetails()->get_Location());
ASSERT_EQ(signingTime.ToUniversalTime(), options->get_DigitalSignatureDetails()->get_SignatureDate().ToUniversalTime());
doc->Save(ArtifactsDir + u"PdfSaveOptions.PdfDigitalSignature.pdf", options);

◆ get_Reason()

System::String Aspose::Words::Saving::PdfDigitalSignatureDetails::get_Reason ( ) const

Gets or sets the reason for the signing.

Examples

Shows how to sign a generated PDF document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Contents of signed PDF.");
SharedPtr<CertificateHolder> certificateHolder = CertificateHolder::Create(MyDir + u"morzal.pfx", u"aw");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
auto options = MakeObject<PdfSaveOptions>();
// Configure the "DigitalSignatureDetails" object of the "SaveOptions" object to
// digitally sign the document as we render it with the "Save" method.
options->set_DigitalSignatureDetails(MakeObject<PdfDigitalSignatureDetails>(certificateHolder, u"Test Signing", u"My Office", signingTime));
options->get_DigitalSignatureDetails()->set_HashAlgorithm(PdfDigitalSignatureHashAlgorithm::Sha256);
ASSERT_EQ(u"Test Signing", options->get_DigitalSignatureDetails()->get_Reason());
ASSERT_EQ(u"My Office", options->get_DigitalSignatureDetails()->get_Location());
ASSERT_EQ(signingTime.ToUniversalTime(), options->get_DigitalSignatureDetails()->get_SignatureDate().ToUniversalTime());
doc->Save(ArtifactsDir + u"PdfSaveOptions.PdfDigitalSignature.pdf", options);

◆ get_SignatureDate()

System::DateTime Aspose::Words::Saving::PdfDigitalSignatureDetails::get_SignatureDate ( ) const

Gets or sets the date of the signing.

The default value is the current time.

This value will appear in the digital signature as an unverified computer time.

Examples

Shows how to sign a generated PDF document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Contents of signed PDF.");
SharedPtr<CertificateHolder> certificateHolder = CertificateHolder::Create(MyDir + u"morzal.pfx", u"aw");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
auto options = MakeObject<PdfSaveOptions>();
// Configure the "DigitalSignatureDetails" object of the "SaveOptions" object to
// digitally sign the document as we render it with the "Save" method.
options->set_DigitalSignatureDetails(MakeObject<PdfDigitalSignatureDetails>(certificateHolder, u"Test Signing", u"My Office", signingTime));
options->get_DigitalSignatureDetails()->set_HashAlgorithm(PdfDigitalSignatureHashAlgorithm::Sha256);
ASSERT_EQ(u"Test Signing", options->get_DigitalSignatureDetails()->get_Reason());
ASSERT_EQ(u"My Office", options->get_DigitalSignatureDetails()->get_Location());
ASSERT_EQ(signingTime.ToUniversalTime(), options->get_DigitalSignatureDetails()->get_SignatureDate().ToUniversalTime());
doc->Save(ArtifactsDir + u"PdfSaveOptions.PdfDigitalSignature.pdf", options);

◆ get_TimestampSettings()

System::SharedPtr<Aspose::Words::Saving::PdfDigitalSignatureTimestampSettings> Aspose::Words::Saving::PdfDigitalSignatureDetails::get_TimestampSettings ( ) const

Gets or sets the digital signature timestamp settings.

The default value is null and the digital signature will not be time-stamped. When this property is set to a valid PdfDigitalSignatureTimestampSettings object, then the digital signature in the PDF document will be time-stamped.

Examples

Shows how to sign a saved PDF document digitally and timestamp it.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Signed PDF contents.");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
auto options = MakeObject<PdfSaveOptions>();
// Create a digital signature and assign it to our SaveOptions object to sign the document when we save it to PDF.
SharedPtr<CertificateHolder> certificateHolder = CertificateHolder::Create(MyDir + u"morzal.pfx", u"aw");
options->set_DigitalSignatureDetails(
MakeObject<PdfDigitalSignatureDetails>(certificateHolder, u"Test Signing", u"Aspose Office", System::DateTime::get_Now()));
// Create a timestamp authority-verified timestamp.
options->get_DigitalSignatureDetails()->set_TimestampSettings(
MakeObject<PdfDigitalSignatureTimestampSettings>(u"https://freetsa.org/tsr", u"JohnDoe", u"MyPassword"));
// The default lifespan of the timestamp is 100 seconds.
ASPOSE_ASSERT_EQ(100.0, options->get_DigitalSignatureDetails()->get_TimestampSettings()->get_Timeout().get_TotalSeconds());
// We can set our timeout period via the constructor.
options->get_DigitalSignatureDetails()->set_TimestampSettings(
MakeObject<PdfDigitalSignatureTimestampSettings>(u"https://freetsa.org/tsr", u"JohnDoe", u"MyPassword", System::TimeSpan::FromMinutes(30)));
ASPOSE_ASSERT_EQ(1800.0, options->get_DigitalSignatureDetails()->get_TimestampSettings()->get_Timeout().get_TotalSeconds());
ASSERT_EQ(u"https://freetsa.org/tsr", options->get_DigitalSignatureDetails()->get_TimestampSettings()->get_ServerUrl());
ASSERT_EQ(u"JohnDoe", options->get_DigitalSignatureDetails()->get_TimestampSettings()->get_UserName());
ASSERT_EQ(u"MyPassword", options->get_DigitalSignatureDetails()->get_TimestampSettings()->get_Password());
// The "Save" method will apply our signature to the output document at this time.
doc->Save(ArtifactsDir + u"PdfSaveOptions.PdfDigitalSignatureTimestamp.pdf", options);

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Saving::PdfDigitalSignatureDetails::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

virtual bool Aspose::Words::Saving::PdfDigitalSignatureDetails::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ set_CertificateHolder()

void Aspose::Words::Saving::PdfDigitalSignatureDetails::set_CertificateHolder ( const System::SharedPtr< Aspose::Words::DigitalSignatures::CertificateHolder > &  value)

Returns the certificate holder object that contains the certificate was used to sign the document.

◆ set_HashAlgorithm()

void Aspose::Words::Saving::PdfDigitalSignatureDetails::set_HashAlgorithm ( Aspose::Words::Saving::PdfDigitalSignatureHashAlgorithm  value)

◆ set_Location()

void Aspose::Words::Saving::PdfDigitalSignatureDetails::set_Location ( const System::String value)

◆ set_Reason()

void Aspose::Words::Saving::PdfDigitalSignatureDetails::set_Reason ( const System::String value)

◆ set_SignatureDate()

void Aspose::Words::Saving::PdfDigitalSignatureDetails::set_SignatureDate ( System::DateTime  value)

◆ set_TimestampSettings()

void Aspose::Words::Saving::PdfDigitalSignatureDetails::set_TimestampSettings ( const System::SharedPtr< Aspose::Words::Saving::PdfDigitalSignatureTimestampSettings > &  value)

◆ Type()

static const System::TypeInfo& Aspose::Words::Saving::PdfDigitalSignatureDetails::Type ( )
static