Xceed Words for .NET v5.0 Documentation
Xceed.Document.NET Assembly / Xceed.Document.NET Namespace / Document Class / AddPasswordProtection Method
Defines the type of restrictions that will be applied to the Document.
Defines the password that will be used to protect the Document.

Defines the hashing algorithm that will be used to encrypt the specified password.

If no hashing algorithm is specified, the SHA-512 algorithm will be used by default to encrypt the password.

 

Example


In This Topic
    AddPasswordProtection Method
    In This Topic

    Protects the Document from modifications by adding a protection password.

    Syntax
    'Declaration
     
    Public Sub AddPasswordProtection( _
       ByVal editRestrictions As EditRestrictions, _
       ByVal password As String, _
       Optional ByVal hashAlgorithm As HashAlgorithm _
    ) 
    'Usage
     
    Dim instance As Document
    Dim editRestrictions As EditRestrictions
    Dim password As String
    Dim hashAlgorithm As HashAlgorithm
     
    instance.AddPasswordProtection(editRestrictions, password, hashAlgorithm)
    public void AddPasswordProtection( 
       EditRestrictions editRestrictions,
       string password,
       HashAlgorithm hashAlgorithm
    )

    Parameters

    editRestrictions
    Defines the type of restrictions that will be applied to the Document.
    password
    Defines the password that will be used to protect the Document.
    hashAlgorithm

    Defines the hashing algorithm that will be used to encrypt the specified password.

    If no hashing algorithm is specified, the SHA-512 algorithm will be used by default to encrypt the password.

     

    Remarks
    It is important to make sure that the selected HashAlgorithm is supported in the context of the Document's encryption settings.
    Example
    myDocument.AddPasswordProtection(EditRestrictions.ReadOnly, "SecurePassword123", HashAlgorithm.Sha256);
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 7, Windows, 11, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also