Udostępnij za pośrednictwem


Właściwość WorkbookBase.PasswordEncryptionKeyLength —

Pobiera długość klucza algorytmu, który program Microsoft Office Excel używa podczas szyfrowania hasła dla skoroszytu.

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 ReadOnly Property PasswordEncryptionKeyLength As Integer
public int PasswordEncryptionKeyLength { get; }

Wartość właściwości

Typ: System.Int32
Długość klucza algorytmu używanego przez program Excel podczas szyfrowania hasła dla skoroszytu.

Uwagi

Użycie SetPasswordEncryptionOptions metodę, aby określić, czy program Excel szyfruje właściwości pliku dla określonego skoroszytu zabezpieczonego hasłem.

Przykłady

Poniższy przykład kodu sprawdza wartość HasPassword właściwość w celu określenia, czy skoroszyt jest chroniony hasłem.Jeśli skoroszyt nie jest chroniony hasłem, a następnie w przykładzie ustawiany jest Password właściwość, aby hasło otrzymane od danych wprowadzonych przez użytkownika, a następnie wywołuje SetPasswordEncryptionOptions metody, aby ustawić algorytmu szyfrowania, ustawienie długości kluczy, ustawienie nazwę dostawcy szyfrowania i włączyć szyfrowanie właściwości pliku.Przykład następnie wyświetlana jest wartość PasswordEncryptionProvider, PasswordEncryptionAlgorithm, PasswordEncryptionKeyLength, i PasswordEncryptionFileProperties właściwości w arkuszu Sheet1.W tym przykładzie zakłada się, że metoda GetPasswordFromUserInput jest zdefiniowany w innym miejscu.

Ten przykład dotyczy dostosowywania 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