次の方法で共有


WorkbookBase.SetPasswordEncryptionOptions メソッド

パスワードを使ってブックを暗号化するためのオプションを設定します。

名前空間:  Microsoft.Office.Tools.Excel
アセンブリ:  Microsoft.Office.Tools.Excel.v4.0.Utilities (Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 内)

構文

'宣言
Public Sub SetPasswordEncryptionOptions ( _
    passwordEncryptionProvider As Object, _
    passwordEncryptionAlgorithm As Object, _
    passwordEncryptionKeyLength As Object, _
    passwordEncryptionFileProperties As Object _
)
public void SetPasswordEncryptionOptions(
    Object passwordEncryptionProvider,
    Object passwordEncryptionAlgorithm,
    Object passwordEncryptionKeyLength,
    Object passwordEncryptionFileProperties
)

パラメーター

  • passwordEncryptionProvider
    型: System.Object
    暗号化プロバイダーの文字列 (大文字と小文字を区別します) です。
  • passwordEncryptionAlgorithm
    型: System.Object
    アルゴリズムの短い名前の文字列 ("RC4" など。大文字と小文字を区別) です。
  • passwordEncryptionKeyLength
    型: System.Object
    暗号キーの長さ (40 以下の 8 の倍数) です。
  • passwordEncryptionFileProperties
    型: System.Object
    true (既定値) の場合、プロパティが暗号化されます。

解説

PasswordEncryptionProvider、PasswordEncryptionAlgorithm、および PasswordEncryptionKeyLength の各パラメーターは互いに独立していません。 選択された暗号化プロバイダーによって、選択可能な一連のアルゴリズムとキーの長さが制限されます。

PasswordEncryptionKeyLength パラメーターでは、キーの長さの範囲に固有の制限はありません。 この範囲と暗号化アルゴリズムは、暗号化サービス プロバイダーによって決定されます。

省略可能なパラメーター

省略可能なパラメーターについては、「Office ソリューションの省略可能なパラメーター」を参照してください。

次のコード例では、HasPassword プロパティの値をチェックし、ブックがパスワードで保護されているかどうかを確認します。 ブックがパスワードで保護されていない場合は、ユーザー入力から取得したパスワードで Password プロパティを設定し、SetPasswordEncryptionOptions メソッドを呼び出して暗号化アルゴリズム、キーの長さ、暗号化プロバイダーの名前を設定し、ファイル プロパティの暗号化を有効にします。 次に、ワークシート Sheet1 内の PasswordEncryptionProviderPasswordEncryptionAlgorithmPasswordEncryptionKeyLength、および PasswordEncryptionFileProperties の各プロパティの値を表示します。 この例では、GetPasswordFromUserInput メソッドが他の場所で定義されていることを前提としています。

この例は、ドキュメント レベルのカスタマイズ用に作成されています。

Private Sub WorkbookPasswordOptions()
    If Not Me.HasPassword Then
        Me.Password = GetPasswordFromUserInput()
        Me.SetPasswordEncryptionOptions( _
            "Microsoft RSA SChannel Cryptographic Provider", _
            "RC4", 128, True)
    End If

    ' Display the password properties in Sheet1.
    Globals.Sheet1.Range("A1").Value2 = _
        "Password Encryption Provider:"
    Globals.Sheet1.Range("A2").Value2 = _
        "Password Encryption Algorithm:"
    Globals.Sheet1.Range("A3").Value2 = _
        "Password Encryption Key Length:"
    Globals.Sheet1.Range("A4").Value2 = _
        "Password Encryption File Properties:"
    Globals.Sheet1.Range("A1", "A4").Columns.AutoFit()

    Globals.Sheet1.Range("B1").Value2 = _
        Me.PasswordEncryptionProvider
    Globals.Sheet1.Range("B2").Value2 = _
        Me.PasswordEncryptionAlgorithm
    Globals.Sheet1.Range("B3").Value2 = _
        Me.PasswordEncryptionKeyLength
    Globals.Sheet1.Range("B4").Value2 = _
        Me.PasswordEncryptionFileProperties
    Globals.Sheet1.Range("B1", "B4").Columns.AutoFit()
End Sub
private void WorkbookPasswordOptions()
{
    if (!this.HasPassword)
    {
        this.Password = GetPasswordFromUserInput();
        this.SetPasswordEncryptionOptions(
            "Microsoft RSA SChannel Cryptographic Provider",
            "RC4", 128, true);
    }

    // Display the password properties in Sheet1.
    Globals.Sheet1.Range["A1", missing].Value2 =
        "Password Encryption Provider:";
    Globals.Sheet1.Range["A2", missing].Value2 =
        "Password Encryption Algorithm:";
    Globals.Sheet1.Range["A3", missing].Value2 =
        "Password Encryption Key Length:";
    Globals.Sheet1.Range["A4", missing].Value2 =
        "Password Encryption File Properties:";
    Globals.Sheet1.Range["A1", "A4"].Columns.AutoFit();

    Globals.Sheet1.Range["B1", missing].Value2 =
        this.PasswordEncryptionProvider;
    Globals.Sheet1.Range["B2", missing].Value2 =
        this.PasswordEncryptionAlgorithm;
    Globals.Sheet1.Range["B3", missing].Value2 =
        this.PasswordEncryptionKeyLength;
    Globals.Sheet1.Range["B4", missing].Value2 =
        this.PasswordEncryptionFileProperties;
    Globals.Sheet1.Range["B1", "B4"].Columns.AutoFit();
}

.NET Framework セキュリティ

  • 直前の呼び出し元に対する完全な信頼。 このメンバーは、部分的に信頼されているコードから使用することはできません。 詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

WorkbookBase クラス

Microsoft.Office.Tools.Excel 名前空間