Sdílet prostřednictvím


DocumentBase.SetPasswordEncryptionOptions Method

Definition

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

public void SetPasswordEncryptionOptions (string passwordEncryptionProvider, string passwordEncryptionAlgorithm, int passwordEncryptionKeyLength, ref object passwordEncryptionFileProperties);
member this.SetPasswordEncryptionOptions : string * string * int * obj -> unit
Public Sub SetPasswordEncryptionOptions (passwordEncryptionProvider As String, passwordEncryptionAlgorithm As String, passwordEncryptionKeyLength As Integer, Optional ByRef passwordEncryptionFileProperties As Object)

Parameters

passwordEncryptionProvider
String

The name of the encryption provider.

passwordEncryptionAlgorithm
String

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

passwordEncryptionKeyLength
Int32

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

passwordEncryptionFileProperties
Object

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

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 void DocumentSetPasswordEncryptionOptions()
{
    object PasswordEncryptionFileProperties = true;

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

    Me.SetPasswordEncryptionOptions( _
        "Microsoft RSA SChannel Cryptographic Provider", _
        "RC4", 56, True)
End Sub

Remarks

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

Applies to