SslStream 생성자

정의

SslStream 클래스의 새 인스턴스를 초기화합니다.

오버로드

Name Description
SslStream(Stream)

지정된 을 사용하여 클래스의 SslStream 새 인스턴스를 Stream초기화합니다.

SslStream(Stream, Boolean)

지정된 및 스트림 닫기 동작을 SslStream 사용하여 클래스의 새 인스턴스를 Stream 초기화합니다.

SslStream(Stream, Boolean, RemoteCertificateValidationCallback)

지정된 SslStream스트림 닫기 동작 및 인증서 유효성 검사 대리자를 사용하여 클래스의 Stream 새 인스턴스를 초기화합니다.

SslStream(Stream, Boolean, RemoteCertificateValidationCallback, LocalCertificateSelectionCallback)

지정된 SslStream스트림 닫기 동작, 인증서 유효성 검사 대리자 및 인증서 선택 대리자를 사용하여 클래스의 Stream 새 인스턴스를 초기화합니다.

SslStream(Stream, Boolean, RemoteCertificateValidationCallback, LocalCertificateSelectionCallback, EncryptionPolicy)

지정된 을 사용하여 클래스의 SslStream 새 인스턴스를 Stream초기화합니다.

설명

사용자가 제공하는 스트림을 SslStream 닫지 않도록 하려면 생성자를 사용합니다 SslStream .

SslStream(Stream)

Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs

지정된 을 사용하여 클래스의 SslStream 새 인스턴스를 Stream초기화합니다.

public:
 SslStream(System::IO::Stream ^ innerStream);
public SslStream(System.IO.Stream innerStream);
new System.Net.Security.SslStream : System.IO.Stream -> System.Net.Security.SslStream
Public Sub New (innerStream As Stream)

매개 변수

innerStream
Stream

Stream 데이터를 보내고 받는 데 사용되는 SslStream 개체입니다.

예외

innerStream 가 읽을 수 없습니다.

-또는-

innerStream 은 쓸 수 없습니다.

innerStreamnull입니다.

-또는-

innerStream가 같음 Null

설명

암호화 EncryptionPolicy 에 대한 구성 파일에 값이 지정되지 않은 경우 기본값 EncryptionPolicy.RequireEncryption 은 생성되는 인스턴스에 SslStream 대한 것입니다.

암호화 정책이 로 설정된 경우 Null 암호화를 사용해야 합니다 EncryptionPolicy.NoEncryption.

적용 대상

SslStream(Stream, Boolean)

Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs

지정된 및 스트림 닫기 동작을 SslStream 사용하여 클래스의 새 인스턴스를 Stream 초기화합니다.

public:
 SslStream(System::IO::Stream ^ innerStream, bool leaveInnerStreamOpen);
public SslStream(System.IO.Stream innerStream, bool leaveInnerStreamOpen);
new System.Net.Security.SslStream : System.IO.Stream * bool -> System.Net.Security.SslStream
Public Sub New (innerStream As Stream, leaveInnerStreamOpen As Boolean)

매개 변수

innerStream
Stream

Stream 데이터를 보내고 받는 데 사용되는 SslStream 개체입니다.

leaveInnerStreamOpen
Boolean

데이터를 보내고 받는 데 사용되는 개체의 Stream 닫기 동작을 SslStream 나타내는 부울 값입니다. 이 매개 변수는 내부 스트림이 열려 있는지를 나타냅니다.

예외

innerStream 가 읽을 수 없습니다.

-또는-

innerStream 은 쓸 수 없습니다.

innerStreamnull입니다.

-또는-

innerStream가 같음 Null

예제

다음 코드 예제에서는이 생성자를 호출 하는 방법을 보여 줍니다.

static void ProcessClient (TcpClient client)
{
    // A client has connected. Create the
    // SslStream using the client's network stream.
    SslStream sslStream = new SslStream(
        client.GetStream(), false);
    // Authenticate the server but don't require the client to authenticate.
    try
    {
        sslStream.AuthenticateAsServer(serverCertificate, clientCertificateRequired: false, checkCertificateRevocation: true);

        // Display the properties and settings for the authenticated stream.
        DisplaySecurityLevel(sslStream);
        DisplaySecurityServices(sslStream);
        DisplayCertificateInformation(sslStream);
        DisplayStreamProperties(sslStream);

        // Set timeouts for the read and write to 5 seconds.
        sslStream.ReadTimeout = 5000;
        sslStream.WriteTimeout = 5000;
        // Read a message from the client.
        Console.WriteLine("Waiting for client message...");
        string messageData = ReadMessage(sslStream);
        Console.WriteLine("Received: {0}", messageData);

        // Write a message to the client.
        byte[] message = Encoding.UTF8.GetBytes("Hello from the server.<EOF>");
        Console.WriteLine("Sending hello message.");
        sslStream.Write(message);
    }
    catch (AuthenticationException e)
    {
        Console.WriteLine("Exception: {0}", e.Message);
        if (e.InnerException != null)
        {
            Console.WriteLine("Inner exception: {0}", e.InnerException.Message);
        }
        Console.WriteLine ("Authentication failed - closing the connection.");
        sslStream.Close();
        client.Close();
        return;
    }
    finally
    {
        // The client stream will be closed with the sslStream
        // because we specified this behavior when creating
        // the sslStream.
        sslStream.Close();
        client.Close();
    }
}
Private Shared Sub ProcessClient(client As TcpClient)
    ' A client has connected. Create the 
    ' SslStream using the client's network stream.
    Dim sslStream = New SslStream(client.GetStream(), False)

    Try

        sslStream.AuthenticateAsServer(serverCertificate, clientCertificateRequired:=False, checkCertificateRevocation:=True)
        ' Display the properties And settings for the authenticated stream.
        DisplaySecurityLevel(sslStream)
        DisplaySecurityServices(sslStream)
        DisplayCertificateInformation(sslStream)
        DisplayStreamProperties(sslStream)

        ' Set timeouts for the read and write to 5 seconds.
        sslStream.ReadTimeout = 5000
        sslStream.WriteTimeout = 5000

        ' Read a message from the client.   
        Console.WriteLine("Waiting for client message...")
        Dim messageData As String = ReadMessage(sslStream)
        Console.WriteLine("Received: {0}", messageData)

        ' Write a message to the client.
        Dim message As Byte() = Encoding.UTF8.GetBytes("Hello from the server.<EOF>")
        Console.WriteLine("Sending hello message.")
        sslStream.Write(message)
    Catch e As AuthenticationException
        Console.WriteLine("Exception: {0}", e.Message)

        If e.InnerException IsNot Nothing Then
            Console.WriteLine("Inner exception: {0}", e.InnerException.Message)
        End If

        Console.WriteLine("Authentication failed - closing the connection.")
        sslStream.Close()
        client.Close()
        Return
    Finally
        ' The client stream will be closed with the sslStream
        ' because we specified this behavior when creating
        ' the sslStream.
        sslStream.Close()
        client.Close()
    End Try
End Sub

설명

매개 변수를 지정할 true 때 닫는 leaveStreamOpen 것은 스트림에 SslStream 영향을 주지 않습니다. 더 이상 필요하지 않을 때 명시적으로 닫 innerStream 아야 innerStream 합니다.

암호화 EncryptionPolicy 에 대한 구성 파일에 값이 지정되지 않은 경우 기본값 EncryptionPolicy.RequireEncryption 은 생성되는 인스턴스에 SslStream 대한 것입니다.

암호화 정책이 로 설정된 경우 Null 암호화를 사용해야 합니다 EncryptionPolicy.NoEncryption.

적용 대상

SslStream(Stream, Boolean, RemoteCertificateValidationCallback)

Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs

지정된 SslStream스트림 닫기 동작 및 인증서 유효성 검사 대리자를 사용하여 클래스의 Stream 새 인스턴스를 초기화합니다.

public:
 SslStream(System::IO::Stream ^ innerStream, bool leaveInnerStreamOpen, System::Net::Security::RemoteCertificateValidationCallback ^ userCertificateValidationCallback);
public SslStream(System.IO.Stream innerStream, bool leaveInnerStreamOpen, System.Net.Security.RemoteCertificateValidationCallback? userCertificateValidationCallback);
public SslStream(System.IO.Stream innerStream, bool leaveInnerStreamOpen, System.Net.Security.RemoteCertificateValidationCallback userCertificateValidationCallback);
new System.Net.Security.SslStream : System.IO.Stream * bool * System.Net.Security.RemoteCertificateValidationCallback -> System.Net.Security.SslStream
Public Sub New (innerStream As Stream, leaveInnerStreamOpen As Boolean, userCertificateValidationCallback As RemoteCertificateValidationCallback)

매개 변수

innerStream
Stream

Stream 데이터를 보내고 받는 데 사용되는 SslStream 개체입니다.

leaveInnerStreamOpen
Boolean

데이터를 보내고 받는 데 사용되는 개체의 Stream 닫기 동작을 SslStream 나타내는 부울 값입니다. 이 매개 변수는 내부 스트림이 열려 있는지를 나타냅니다.

userCertificateValidationCallback
RemoteCertificateValidationCallback

원격 당사자가 RemoteCertificateValidationCallback 제공한 인증서의 유효성을 검사하는 대리자입니다.

예외

innerStream 가 읽을 수 없습니다.

-또는-

innerStream 은 쓸 수 없습니다.

innerStreamnull입니다.

-또는-

innerStream가 같음 Null

예제

다음 코드 예제에서는 인증의 클라이언트 부분을 만들고 SslStream 시작합니다.

// Create a TCP/IP client socket.
// machineName is the host running the server application.
TcpClient client = new TcpClient(machineName,5000);
Console.WriteLine("Client connected.");
// Create an SSL stream that will close the client's stream.
SslStream sslStream = new SslStream(
    client.GetStream(),
    false,
    new RemoteCertificateValidationCallback (ValidateServerCertificate),
    null
    );
// The server name must match the name on the server certificate.
try
{
    sslStream.AuthenticateAsClient(serverName);
}
catch (AuthenticationException e)
{
    Console.WriteLine("Exception: {0}", e.Message);
    if (e.InnerException != null)
    {
        Console.WriteLine("Inner exception: {0}", e.InnerException.Message);
    }
    Console.WriteLine ("Authentication failed - closing the connection.");
    client.Close();
    return;
}
' Create a TCP/IP client socket.
' machineName is the host running the server application.
Dim client = New TcpClient(machineName, 5000)
Console.WriteLine("Client connected.")

' Create an SSL stream that will close the client's stream.
Dim sslStream = New SslStream(
    client.GetStream(), False, 
    New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate), Nothing)

' The server name must match the name on the server certificate.
Try
    sslStream.AuthenticateAsClient(serverName)
Catch e As AuthenticationException
    Console.WriteLine("Exception: {0}", e.Message)

    If e.InnerException IsNot Nothing Then
        Console.WriteLine("Inner exception: {0}", e.InnerException.Message)
    End If

    Console.WriteLine("Authentication failed - closing the connection.")
    client.Close()
    Return
End Try

설명

매개 변수를 지정할 true 때 닫는 leaveStreamOpen 것은 스트림에 SslStream 영향을 주지 않습니다. 더 이상 필요하지 않을 때 명시적으로 닫 innerStream 아야 innerStream 합니다.

userCertificateValidationCallback 대리자의 certificateErrors 인수에는 채널 SSPI(보안 지원 공급자 인터페이스)에서 반환된 Windows 오류 코드가 포함됩니다. 대리자가 호출한 userCertificateValidationCallback 메서드의 반환 값은 인증 성공 여부를 결정합니다.

대리자의 메서드가 호출될 때 userCertificateValidationCallback 보안 프로토콜 및 암호화 알고리즘이 이미 선택되어 있습니다. 이 메서드를 사용하여 선택한 암호화 알고리즘과 강도가 애플리케이션에 충분한지 여부를 확인할 수 있습니다. 그렇지 않은 경우 메서드가 반환 false 되어 생성되지 않도록 SslStream 해야 합니다.

암호화 EncryptionPolicy 에 대한 구성 파일에 값이 지정되지 않은 경우 기본값 EncryptionPolicy.RequireEncryption 은 생성되는 인스턴스에 SslStream 대한 것입니다.

암호화 정책이 로 설정된 경우 Null 암호화를 사용해야 합니다 EncryptionPolicy.NoEncryption.

메모

.NET SSL 세션이 만들어질 때 캐시하고 가능한 경우 후속 요청에 캐시된 세션을 다시 사용하려고 시도합니다. SSL 세션을 다시 사용하려고 할 때 프레임워크는 인증 중에 제공된 첫 번째 요소를 X509Certificate2Collection 사용하거나(있는 경우) 인증서 컬렉션이 비어 있는 경우 익명 세션을 다시 사용하려고 합니다.

메모

클라이언트 인증서는 SSL 버전 2 프로토콜에서 지원되지 않습니다.

적용 대상

SslStream(Stream, Boolean, RemoteCertificateValidationCallback, LocalCertificateSelectionCallback)

Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs

지정된 SslStream스트림 닫기 동작, 인증서 유효성 검사 대리자 및 인증서 선택 대리자를 사용하여 클래스의 Stream 새 인스턴스를 초기화합니다.

public:
 SslStream(System::IO::Stream ^ innerStream, bool leaveInnerStreamOpen, System::Net::Security::RemoteCertificateValidationCallback ^ userCertificateValidationCallback, System::Net::Security::LocalCertificateSelectionCallback ^ userCertificateSelectionCallback);
public SslStream(System.IO.Stream innerStream, bool leaveInnerStreamOpen, System.Net.Security.RemoteCertificateValidationCallback? userCertificateValidationCallback, System.Net.Security.LocalCertificateSelectionCallback? userCertificateSelectionCallback);
public SslStream(System.IO.Stream innerStream, bool leaveInnerStreamOpen, System.Net.Security.RemoteCertificateValidationCallback userCertificateValidationCallback, System.Net.Security.LocalCertificateSelectionCallback userCertificateSelectionCallback);
new System.Net.Security.SslStream : System.IO.Stream * bool * System.Net.Security.RemoteCertificateValidationCallback * System.Net.Security.LocalCertificateSelectionCallback -> System.Net.Security.SslStream
Public Sub New (innerStream As Stream, leaveInnerStreamOpen As Boolean, userCertificateValidationCallback As RemoteCertificateValidationCallback, userCertificateSelectionCallback As LocalCertificateSelectionCallback)

매개 변수

innerStream
Stream

Stream 데이터를 보내고 받는 데 사용되는 SslStream 개체입니다.

leaveInnerStreamOpen
Boolean

데이터를 보내고 받는 데 사용되는 개체의 Stream 닫기 동작을 SslStream 나타내는 부울 값입니다. 이 매개 변수는 내부 스트림이 열려 있는지를 나타냅니다.

userCertificateValidationCallback
RemoteCertificateValidationCallback

원격 당사자가 RemoteCertificateValidationCallback 제공한 인증서의 유효성을 검사하는 대리자입니다.

userCertificateSelectionCallback
LocalCertificateSelectionCallback

LocalCertificateSelectionCallback 인증에 사용되는 인증서를 선택할 책임이 있는 대리자입니다.

예외

innerStream 가 읽을 수 없습니다.

-또는-

innerStream 은 쓸 수 없습니다.

innerStreamnull입니다.

-또는-

innerStream가 같음 Null

예제

다음 코드 예제에서는이 생성자를 호출 하는 방법을 보여 줍니다. 이 예제는 클래스에 제공된 더 큰 예제의 SslStream 일부입니다.

// Server name must match the host name and the name on the host's certificate.
serverName = args[0];
// Create a TCP/IP client socket.
TcpClient client = new TcpClient(serverName,5000);
Console.WriteLine("Client connected.");
// Create an SSL stream that will close the client's stream.
SslStream sslStream = new SslStream(
    client.GetStream(),
    false,
    new RemoteCertificateValidationCallback (ValidateServerCertificate),
    new LocalCertificateSelectionCallback(SelectLocalCertificate)
    );
' Server name must match the host name and the name on the host's certificate. 
serverName = args(0)
' Create a TCP/IP client socket.
Dim client As New TcpClient(serverName, 5000)
Console.WriteLine("Client connected.")
' Create an SSL stream that will close the client's stream.
Dim sslStream As New SslStream(
    client.GetStream(), False, 
    New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate), 
    New LocalCertificateSelectionCallback(AddressOf SelectLocalCertificate))

설명

매개 변수를 지정할 true 때 닫는 leaveStreamOpen 것은 스트림에 SslStream 영향을 주지 않습니다. 더 이상 필요하지 않을 때 명시적으로 닫 innerStream 아야 innerStream 합니다.

userCertificateValidationCallback 대리자의 certificateErrors 인수에는 채널 SSPI(보안 지원 공급자 인터페이스)에서 반환된 Windows 오류 코드가 포함됩니다. 대리자가 호출한 userCertificateValidationCallback 메서드의 반환 값은 인증 성공 여부를 결정합니다.

대리자의 메서드가 호출될 때 userCertificateValidationCallback 보안 프로토콜 및 암호화 알고리즘이 이미 선택되어 있습니다. 이 메서드를 사용하여 선택한 암호화 알고리즘과 강도가 애플리케이션에 충분한지 여부를 확인할 수 있습니다. 그렇지 않은 경우 메서드가 반환 false 되어 생성되지 않도록 SslStream 해야 합니다.

대리자는 userCertificateSelectionCallback 애플리케이션에 여러 인증서가 있고 인증서를 동적으로 선택해야 하는 경우에 유용합니다. "MY" 저장소의 인증서는 대리자가 호출한 메서드에 전달됩니다.

암호화 EncryptionPolicy 에 대한 구성 파일에 값이 지정되지 않은 경우 기본값 EncryptionPolicy.RequireEncryption 은 생성되는 인스턴스에 SslStream 대한 것입니다.

암호화 정책이 로 설정된 경우 Null 암호화를 사용해야 합니다 EncryptionPolicy.NoEncryption.

메모

.NET SSL 세션이 만들어질 때 캐시하고 가능한 경우 후속 요청에 캐시된 세션을 다시 사용하려고 시도합니다. SSL 세션을 다시 사용하려고 할 때 프레임워크는 인증 중에 제공된 첫 번째 요소를 X509Certificate2Collection 사용하거나(있는 경우) 인증서 컬렉션이 비어 있는 경우 익명 세션을 다시 사용하려고 합니다.

적용 대상

SslStream(Stream, Boolean, RemoteCertificateValidationCallback, LocalCertificateSelectionCallback, EncryptionPolicy)

Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.IO.cs
Source:
SslStream.cs
Source:
SslStream.cs

지정된 을 사용하여 클래스의 SslStream 새 인스턴스를 Stream초기화합니다.

public:
 SslStream(System::IO::Stream ^ innerStream, bool leaveInnerStreamOpen, System::Net::Security::RemoteCertificateValidationCallback ^ userCertificateValidationCallback, System::Net::Security::LocalCertificateSelectionCallback ^ userCertificateSelectionCallback, System::Net::Security::EncryptionPolicy encryptionPolicy);
public SslStream(System.IO.Stream innerStream, bool leaveInnerStreamOpen, System.Net.Security.RemoteCertificateValidationCallback? userCertificateValidationCallback, System.Net.Security.LocalCertificateSelectionCallback? userCertificateSelectionCallback, System.Net.Security.EncryptionPolicy encryptionPolicy);
public SslStream(System.IO.Stream innerStream, bool leaveInnerStreamOpen, System.Net.Security.RemoteCertificateValidationCallback userCertificateValidationCallback, System.Net.Security.LocalCertificateSelectionCallback userCertificateSelectionCallback, System.Net.Security.EncryptionPolicy encryptionPolicy);
new System.Net.Security.SslStream : System.IO.Stream * bool * System.Net.Security.RemoteCertificateValidationCallback * System.Net.Security.LocalCertificateSelectionCallback * System.Net.Security.EncryptionPolicy -> System.Net.Security.SslStream
Public Sub New (innerStream As Stream, leaveInnerStreamOpen As Boolean, userCertificateValidationCallback As RemoteCertificateValidationCallback, userCertificateSelectionCallback As LocalCertificateSelectionCallback, encryptionPolicy As EncryptionPolicy)

매개 변수

innerStream
Stream

Stream 데이터를 보내고 받는 데 사용되는 SslStream 개체입니다.

leaveInnerStreamOpen
Boolean

데이터를 보내고 받는 데 사용되는 개체의 Stream 닫기 동작을 SslStream 나타내는 부울 값입니다. 이 매개 변수는 내부 스트림이 열려 있는지를 나타냅니다.

userCertificateValidationCallback
RemoteCertificateValidationCallback

원격 당사자가 RemoteCertificateValidationCallback 제공한 인증서의 유효성을 검사하는 대리자입니다.

userCertificateSelectionCallback
LocalCertificateSelectionCallback

LocalCertificateSelectionCallback 인증에 사용되는 인증서를 선택할 책임이 있는 대리자입니다.

encryptionPolicy
EncryptionPolicy

EncryptionPolicy 사용할 수 있습니다.

예외

innerStream 가 읽을 수 없습니다.

-또는-

innerStream 은 쓸 수 없습니다.

-또는-

encryptionPolicy 가 잘못되었습니다.

innerStreamnull입니다.

-또는-

innerStream가 같음 Null

설명

매개 변수가 .로 설정된 경우 Null 암호화를 encryptionPolicy 사용해야 합니다 EncryptionPolicy.NoEncryption.

적용 대상