このクイック チュートリアルでは、PFX 証明書ファイルから C# を使用して PowerPoint に署名を挿入する方法 について説明します。これには、環境構成、段階的なプログラム ロジック、および C# を使用して PowerPoint にデジタル署名を追加するための実行可能なサンプル コードに関する情報が含まれています。また、プレゼンテーション ファイルにデジタル署名コメントを追加して PPTX ファイルとして保存する前に、デジタル署名コメントを設定する方法についても説明します。
C# を使用して PowerPoint に署名を挿入する手順
- Aspose.Slides for .NET を追加してプレゼンテーションに署名するように環境を構成する
- PFX 証明書から署名する必要がある Presentation オブジェクトにファイルを作成またはロードします
- PFX 証明書ファイル部分とパスワードを提供して、DigitalSignature クラス オブジェクトをインスタンス化します
- 挿入する署名の必要なプロパティを設定します
- 新しく作成した署名をプレゼンテーションの署名コレクションに追加します
- 新しい署名が追加された更新されたプレゼンテーションを保存します
これらの手順では、C# を使用して PowerPoint で署名を追加する方法 のプロセスについて説明し、必要なリソース、プログラム シーケンス、およびサンプル コードへのリンクを共有します。 Presentation クラスを使用してプレゼンテーションを作成またはロードしたり、DigitalSignature クラスを使用して PFX 証明書をロードしたりするなど、タスクを実行するために必要なすべてのクラス、メソッド、およびプロパティを紹介します。この機能は現在、PPTX ファイルでのみ利用可能であることに注意してください。
C# を使用して PowerPoint にデジタル署名を挿入するコード
using Aspose.Cells; | |
using Aspose.Slides; | |
using System; | |
namespace AsposeProjects | |
{ | |
class Program | |
{ | |
static void Main(string[] args) // Main function to sign a presentation in C# | |
{ | |
// If you are using .NET Framework 4.7.0 or higher, uncomment the following lines of codes as this framework does not take sha1 | |
//AppContext.SetSwitch("Switch.System.Security.Cryptography.Xml.UseInsecureHashAlgorithms", true); | |
//AppContext.SetSwitch("Switch.System.Security.Cryptography.Pkcs.UseInsecureHashAlgorithms", true); | |
// Initialize license | |
Aspose.Slides.License lic = new Aspose.Slides.License(); | |
lic.SetLicense("Aspose.Total.lic"); | |
// Create or load the presentation | |
Presentation presentation = new Presentation(); | |
// Instantiate the DigitalSignature by providing the PFX file and the password | |
DigitalSignature digitalSignature = new DigitalSignature("certificate.pfx", "mypass"); | |
// Set comments for the signature for user assistance | |
digitalSignature.Comments = "Test comments for the digital signature"; | |
// Insert the new signature to the signatures collection | |
presentation.DigitalSignatures.Add(digitalSignature); | |
// Save presentation | |
presentation.Save("SomePresentationSigned.pptx", Aspose.Slides.Export.SaveFormat.Pptx); | |
Console.WriteLine("Done"); | |
} | |
} | |
} |
このコードは、C# を使用して PowerPoint に署名を追加する方法 を示しています。最初のステップでは、他の多くのコンストラクターを提供するプレゼンテーション クラスを使用してプレゼンテーション ファイルをロード/作成し、ディスクではなくストリームからファイルをロードし、読み込みプロセスをカスタマイズするための LoadOptions クラス オブジェクト。同様に、Comments プロパティを使用して、デジタル署名をプレゼンテーションに追加する前にコメントを設定できます。 4.7.0 以上の .NET Framework では、プログラムの先頭にある 2 行のコードのコメントを解除する必要があることに注意してください。
この鋭いチュートリアルでは、C# を使用して PowerPoint に署名を追加する方法 について説明します。プレゼンテーションを暗号化するプロセスを知りたい場合は、C# .NET で PowerPoint プレゼンテーションを保護する方法 の記事を参照してください。