Udostępnij za pośrednictwem


Metoda WorkbookBase.SetPasswordEncryptionOptions —

Ustawia opcje dla skoroszytu za pomocą hasła szyfrowania.

Przestrzeń nazw:  Microsoft.Office.Tools.Excel
Zestaw:  Microsoft.Office.Tools.Excel.v4.0.Utilities (w Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Składnia

'Deklaracja
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
)

Parametry

  • passwordEncryptionProvider
    Typ: System.Object
    Ciąg liter dostawca szyfrowania.
  • passwordEncryptionAlgorithm
    Typ: System.Object
    Ciąg liter algorytmiczny krótkiej nazwy (tj.) "RC4").
  • passwordEncryptionKeyLength
    Typ: System.Object
    Długość klucza szyfrowania, który jest wielokrotnością liczby 8 (40 lub większej).
  • passwordEncryptionFileProperties
    Typ: System.Object
    true (domyślnie), aby zaszyfrować właściwości pliku.

Uwagi

PasswordEncryptionProvider, PasswordEncryptionAlgorithm, I PasswordEncryptionKeyLength parametry nie są niezależne od siebie.Dostawca szyfrowania wybranych ogranicza zestaw algorytmów i długość klucza, który może być wybrany.

Dla PasswordEncryptionKeyLength parametr nie ma limitu nieodłączne na zakres długości klucza.Zakres jest określana przez dostawcę usług kryptograficznych, który również określa algorytm kryptograficzny.

Parametry opcjonalne

Informacje na temat parametrów opcjonalnych można wyświetlić na Parametry opcjonalne w rozwiązaniach Office.

Przykłady

Poniższy przykład kodu sprawdza wartość właściwości HasPassword, aby ustalić, czy dany skoroszyt jest chroniony hasłem.Jeśli skoroszyt nie jest chroniony hasłem, wtedy przykład dostosowuje właściwość Password do hasła otrzymanego z danych wejściowych użytkownika, następnie wywołuje metodę SetPasswordEncryptionOptions, aby ustawić algorytm szyfrowania, długość klucza i nazwę dostawcy szyfrowania oraz włączyć szyfrowanie właściwości pliku.Przykład następnie wyświetla jest wartości PasswordEncryptionProvider, PasswordEncryptionAlgorithm, PasswordEncryptionKeyLength i właściwości PasswordEncryptionFileProperties w arkuszu Sheet1.W tym przykładzie zakłada się, że metoda GetPasswordFromUserInput została zdefiniowana w innym miejscu.

Ten przykład dotyczy dostosowywania na poziomie dokumentu.

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"].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 =
        this.PasswordEncryptionProvider;
    Globals.Sheet1.Range["B2"].Value2 =
        this.PasswordEncryptionAlgorithm;
    Globals.Sheet1.Range["B3"].Value2 =
        this.PasswordEncryptionKeyLength;
    Globals.Sheet1.Range["B4"].Value2 =
        this.PasswordEncryptionFileProperties;
    Globals.Sheet1.Range["B1", "B4"].Columns.AutoFit();
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

WorkbookBase Klasa

Przestrzeń nazw Microsoft.Office.Tools.Excel