Partager via


DocumentBase.SetPasswordEncryptionOptions Method

Sets the options Microsoft Office Word uses for encrypting documents with passwords.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

Syntax

'Declaration
Public Sub SetPasswordEncryptionOptions ( _
    passwordEncryptionProvider As String, _
    passwordEncryptionAlgorithm As String, _
    passwordEncryptionKeyLength As Integer, _
    ByRef passwordEncryptionFileProperties As Object _
)
public void SetPasswordEncryptionOptions(
    string passwordEncryptionProvider,
    string passwordEncryptionAlgorithm,
    int passwordEncryptionKeyLength,
    ref Object passwordEncryptionFileProperties
)

Parameters

  • passwordEncryptionProvider
    Type: System.String

    The name of the encryption provider.

  • passwordEncryptionAlgorithm
    Type: System.String

    The name of the encryption algorithm. Word supports stream-encrypted algorithms.

  • passwordEncryptionKeyLength
    Type: System.Int32

    The encryption key length. Must be a multiple of 8, starting at 40.

  • passwordEncryptionFileProperties
    Type: System.Object%

    true for Word to encrypt file properties. Default is true.

Remarks

For enhanced security, do not use Weak Encryption (XOR) (also called "OfficeXor") or "Office97/2000 Compatible" (also called "OfficeStandard") algorithms.

Examples

The following code example uses the SetPasswordEncryptionOptions method to use the RC4 encryption algorithm. The code specifies a key length of 56, enables file property encryption, and sets the name of the encryption provider to the string "Microsoft RSA SChannel Cryptographic Provider". To use this example, run it from the ThisDocument class in a document-level project.

Private Sub DocumentSetPasswordEncryptionOptions()

    Me.SetPasswordEncryptionOptions( _
        "Microsoft RSA SChannel Cryptographic Provider", _
        "RC4", 56, True)
End Sub
private void DocumentSetPasswordEncryptionOptions()
{
    object PasswordEncryptionFileProperties = true;

    this.SetPasswordEncryptionOptions(
        "Microsoft RSA SChannel Cryptographic Provider",
        "RC4", 56, ref PasswordEncryptionFileProperties);
}

.NET Framework Security

See Also

Reference

DocumentBase Class

Microsoft.Office.Tools.Word Namespace