Spire.Cloud.Word provides the EncryptApi interface to encrypt Word documents with password. This article demonstrates the same.
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
namespace EncryptWord
{
class Program
{
static string appId = "App ID";
static string appKey = "App Key";
static string baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base URL
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
//Create a EncryptApi object
static EncryptApi encryptApi = new EncryptApi(wordConfiguration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.docx";
//Specify the path and name of the generated document
string destFilePath = "output/EncryptDocument.docx";
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
//Specify the old password
string oldPassword = null;
//Specify the new password
string newPassword = "abc-123";
//Call EncryptDocument method to encrypt the document with password
encryptApi.EncryptDocument(name, destFilePath, folder, storage, oldPassword, newPassword);
}
}
}