DocumentBase.SetPasswordEncryptionOptions 方法

設定 Microsoft Office Word 以密碼加密文件時使用的選項。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v4.0.Utilities (在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

語法

'宣告
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
)

參數

  • passwordEncryptionProvider
    型別:System.String
    加密提供者的名稱。
  • passwordEncryptionAlgorithm
    型別:System.String
    加密演算法的名稱。Word 支援資料流加密演算法。
  • passwordEncryptionKeyLength
    型別:System.Int32
    加密金鑰長度。必須是 8 的倍數,從 40 起算。
  • passwordEncryptionFileProperties
    型別:System.Object%
    true 表示 Word 加密檔案屬性。預設值為 true。

備註

若要加強安全,請勿使用 Weak Encryption (XOR) (也稱為 "OfficeXor") 或 "Office97/2000 Compatible" (也稱為 "OfficeStandard") 演算法。

範例

下列程式碼範例會使用 SetPasswordEncryptionOptions 方法運用 RC4 加密演算法。 程式碼會將指定金鑰長度為 56、啟用檔案屬性加密,並且將加密提供者的名稱設定為字串 "Microsoft RSA SChannel Cryptographic Provider"。 若要使用這個範例,請在文件層級專案中的 ThisDocument 類別執行。

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 安全性

請參閱

參考

DocumentBase 類別

Microsoft.Office.Tools.Word 命名空間