Aspose::Words::DigitalSignatures::DigitalSignatureUtil class
Contents
[
Hide
]DigitalSignatureUtil class
Provides methods for signing document. To learn more, visit the Work with Digital Signatures documentation article.
class DigitalSignatureUtil
Methods
Method | Description |
---|---|
DigitalSignatureUtil() | |
static LoadSignatures(const System::String&) | Loads digital signatures from document. |
static LoadSignatures(const System::SharedPtr<System::IO::Stream>&) | Loads digital signatures from document using stream. |
static LoadSignatures(std::basic_istream<CharType, Traits>&) | |
static RemoveAllSignatures(const System::String&, const System::String&) | Removes all digital signatures from source file and writes unsigned file to destination file. The following formats are compatible for digital signature removal: Doc, Dot, Docx, Dotx, Docm, Odt, Ott. |
static RemoveAllSignatures(const System::SharedPtr<System::IO::Stream>&, const System::SharedPtr<System::IO::Stream>&) | 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.**The following formats are compatible for digital signature removal: Doc, Dot, Docx, Dotx, Docm, Odt, Ott. |
static RemoveAllSignatures(std::basic_istream<CharType, Traits>&, std::basic_ostream<CharType, Traits>&) | |
static Sign(const System::SharedPtr<System::IO::Stream>&, const System::SharedPtr<System::IO::Stream>&, const System::SharedPtr<Aspose::Words::DigitalSignatures::CertificateHolder>&, const System::SharedPtr<Aspose::Words::DigitalSignatures::SignOptions>&) | Signs source document using given CertificateHolder and SignOptions with digital signature and writes signed document to destination stream. Supported formats are: Doc, Dot, Docx, Dotx, Docm, Odt, Ott.Output will be written to the start of stream and stream size will be updated with content length. |
static Sign(const System::String&, const System::String&, const System::SharedPtr<Aspose::Words::DigitalSignatures::CertificateHolder>&, const System::SharedPtr<Aspose::Words::DigitalSignatures::SignOptions>&) | Signs source document using given CertificateHolder and SignOptions with digital signature and writes signed document to destination file. Supported formats are: Doc, Dot, Docx, Dotx, Docm, Odt, Ott. |
static Sign(const System::SharedPtr<System::IO::Stream>&, const System::SharedPtr<System::IO::Stream>&, const System::SharedPtr<Aspose::Words::DigitalSignatures::CertificateHolder>&) | Signs source document using given CertificateHolder with digital signature and writes signed document to destination stream. Supported formats are: Doc, Dot, Docx, Dotx, Docm, Odt, Ott.Output will be written to the start of stream and stream size will be updated with content length. |
static Sign(const System::String&, const System::String&, const System::SharedPtr<Aspose::Words::DigitalSignatures::CertificateHolder>&) | Signs source document using given CertificateHolder with digital signature and writes signed document to destination file. Supported formats are: Doc, Dot, Docx, Dotx, Docm, Odt, Ott. |
static Sign(std::basic_istream<CharType, Traits>&, std::basic_ostream<CharType, Traits>&, System::SharedPtr<Aspose::Words::DigitalSignatures::CertificateHolder>, System::SharedPtr<Aspose::Words::DigitalSignatures::SignOptions>) | |
static Sign(std::basic_istream<CharType, Traits>&, std::basic_ostream<CharType, Traits>&, System::SharedPtr<Aspose::Words::DigitalSignatures::CertificateHolder>) |
Remarks
Since digital signature works with file content rather than Document Object Model these methods are put into a separate class.
Supported formats are: Doc, Dot, Docx, Dotx, Docm, Odt, Ott.
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);
DigitalSignatureUtil::RemoveAllSignatures(streamIn, streamOut);
}
}
// 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());
See Also
- Namespace Aspose::Words::DigitalSignatures
- Library Aspose.Words for C++