ProtectedData.Unprotect 메서드

정의

오버로드

Name Description
Unprotect(Byte[], Byte[], DataProtectionScope)

지정된 바이트 배열의 데이터 암호를 해독하고 암호 해독된 데이터를 포함하는 바이트 배열을 반환합니다.

Unprotect(ReadOnlySpan<Byte>, DataProtectionScope, ReadOnlySpan<Byte>)

지정된 바이트 배열의 데이터 암호를 해독하고 암호 해독된 데이터를 포함하는 바이트 배열을 반환합니다.

Unprotect(ReadOnlySpan<Byte>, DataProtectionScope, Span<Byte>, ReadOnlySpan<Byte>)

지정된 버퍼의 데이터 암호를 해독하고 암호 해독된 데이터를 대상 버퍼에 씁니다.

Unprotect(Byte[], Byte[], DataProtectionScope)

Source:
ProtectedData.cs
Source:
ProtectedData.cs
Source:
ProtectedData.cs
Source:
ProtectedData.cs
Source:
ProtectedData.cs
Source:
ProtectedData.cs
Source:
ProtectedData.cs

지정된 바이트 배열의 데이터 암호를 해독하고 암호 해독된 데이터를 포함하는 바이트 배열을 반환합니다.

public:
 static cli::array <System::Byte> ^ Unprotect(cli::array <System::Byte> ^ encryptedData, cli::array <System::Byte> ^ optionalEntropy, System::Security::Cryptography::DataProtectionScope scope);
public static byte[] Unprotect(byte[] encryptedData, byte[]? optionalEntropy, System.Security.Cryptography.DataProtectionScope scope);
public static byte[] Unprotect(byte[] encryptedData, byte[] optionalEntropy, System.Security.Cryptography.DataProtectionScope scope);
static member Unprotect : byte[] * byte[] * System.Security.Cryptography.DataProtectionScope -> byte[]
Public Shared Function Unprotect (encryptedData As Byte(), optionalEntropy As Byte(), scope As DataProtectionScope) As Byte()

매개 변수

encryptedData
Byte[]

메서드를 사용하여 암호화된 데이터를 포함하는 바이트 배열입니다 Protect(Byte[], Byte[], DataProtectionScope) .

optionalEntropy
Byte[]

데이터를 암호화하는 데 사용되었거나 null 추가 바이트 배열이 사용되지 않은 경우 선택적 추가 바이트 배열입니다.

scope
DataProtectionScope

데이터를 암호화하는 데 사용된 데이터 보호 범위를 지정하는 열거형 값 중 하나입니다.

반품

Byte[]

암호 해독된 데이터를 나타내는 바이트 배열입니다.

예외

매개 변수는 encryptedData .입니다 null.

암호 해독에 실패했습니다.

운영 체제에서 이 메서드를 지원하지 않습니다.

메모리 부족.

.NET Core 및 .NET 5 이상만 해당: Unprotect 메서드에 대한 호출은 Windows 운영 체제에서만 지원됩니다.

예제

다음 코드 예제에서는 데이터 보호를 사용하는 방법을 보여줍니다.

using System;
using System.Security.Cryptography;

public class DataProtectionSample
{
    // Create byte array for additional entropy when using Protect method.
    static byte [] s_additionalEntropy = { 9, 8, 7, 6, 5 };

    public static void Main()
    {
        // Create a simple byte array containing data to be encrypted.
        byte [] secret = { 0, 1, 2, 3, 4, 1, 2, 3, 4 };

        //Encrypt the data.
        byte [] encryptedSecret = Protect( secret );
        Console.WriteLine("The encrypted byte array is:");
        PrintValues(encryptedSecret);

        // Decrypt the data and store in a byte array.
        byte [] originalData = Unprotect( encryptedSecret );
        Console.WriteLine("{0}The original data is:", Environment.NewLine);
        PrintValues(originalData);
    }

    public static byte [] Protect( byte [] data )
    {
        try
        {
            // Encrypt the data using DataProtectionScope.CurrentUser. The result can be decrypted
            // only by the same current user.
            return ProtectedData.Protect( data, s_additionalEntropy, DataProtectionScope.CurrentUser );
        }
        catch (CryptographicException e)
        {
            Console.WriteLine("Data was not encrypted. An error occurred.");
            Console.WriteLine(e.ToString());
            return null;
        }
    }

    public static byte [] Unprotect( byte [] data )
    {
        try
        {
            //Decrypt the data using DataProtectionScope.CurrentUser.
            return ProtectedData.Unprotect( data, s_additionalEntropy, DataProtectionScope.CurrentUser );
        }
        catch (CryptographicException e)
        {
            Console.WriteLine("Data was not decrypted. An error occurred.");
            Console.WriteLine(e.ToString());
            return null;
        }
    }

    public static void PrintValues( Byte[] myArr )
    {
        foreach ( Byte i in myArr )
        {
            Console.Write( "\t{0}", i );
        }
        Console.WriteLine();
    }
}
Imports System.Security.Cryptography



Public Class DataProtectionSample
    ' Create byte array for additional entropy when using Protect method.
    Private Shared s_additionalEntropy As Byte() = {9, 8, 7, 6, 5}


    Public Shared Sub Main()
        ' Create a simple byte array containing data to be encrypted.
        Dim secret As Byte() = {0, 1, 2, 3, 4, 1, 2, 3, 4}

        'Encrypt the data.
        Dim encryptedSecret As Byte() = Protect(secret)
        Console.WriteLine("The encrypted byte array is:")
        PrintValues(encryptedSecret)

        ' Decrypt the data and store in a byte array.
        Dim originalData As Byte() = Unprotect(encryptedSecret)
        Console.WriteLine("{0}The original data is:", Environment.NewLine)
        PrintValues(originalData)

    End Sub


    Public Shared Function Protect(ByVal data() As Byte) As Byte()
        Try
            ' Encrypt the data using DataProtectionScope.CurrentUser. The result can be decrypted
            '  only by the same current user.
            Return ProtectedData.Protect(data, s_additionalEntropy, DataProtectionScope.CurrentUser)
        Catch e As CryptographicException
            Console.WriteLine("Data was not encrypted. An error occurred.")
            Console.WriteLine(e.ToString())
            Return Nothing
        End Try

    End Function


    Public Shared Function Unprotect(ByVal data() As Byte) As Byte()
        Try
            'Decrypt the data using DataProtectionScope.CurrentUser.
            Return ProtectedData.Unprotect(data, s_additionalEntropy, DataProtectionScope.CurrentUser)
        Catch e As CryptographicException
            Console.WriteLine("Data was not decrypted. An error occurred.")
            Console.WriteLine(e.ToString())
            Return Nothing
        End Try

    End Function


    Public Shared Sub PrintValues(ByVal myArr() As [Byte])
        Dim i As [Byte]
        For Each i In myArr
            Console.Write(vbTab + "{0}", i)
        Next i
        Console.WriteLine()

    End Sub
End Class

설명

이 메서드를 사용하여 암호화된 Protect 데이터를 보호 해제하는 데 사용할 수 있습니다. 암호화 중에 매개 변수를 optionalEntropy 사용한 경우 데이터 암호화를 해제하기 위해 매개 변수를 제공해야 합니다.

메모

가장하는 동안 이 메서드를 사용하는 경우 "키가 지정된 상태에서 사용할 수 없습니다."라는 오류가 표시될 수 있습니다. 이 오류를 방지하려면 메서드를 호출하기 전에 가장하려는 사용자의 프로필을 로드합니다.

적용 대상

Unprotect(ReadOnlySpan<Byte>, DataProtectionScope, ReadOnlySpan<Byte>)

Source:
ProtectedData.cs
Source:
ProtectedData.cs
Source:
ProtectedData.cs

지정된 바이트 배열의 데이터 암호를 해독하고 암호 해독된 데이터를 포함하는 바이트 배열을 반환합니다.

public static byte[] Unprotect(ReadOnlySpan<byte> encryptedData, System.Security.Cryptography.DataProtectionScope scope, ReadOnlySpan<byte> optionalEntropy = default);
static member Unprotect : ReadOnlySpan<byte> * System.Security.Cryptography.DataProtectionScope * ReadOnlySpan<byte> -> byte[]
Public Shared Function Unprotect (encryptedData As ReadOnlySpan(Of Byte), scope As DataProtectionScope, Optional optionalEntropy As ReadOnlySpan(Of Byte) = Nothing) As Byte()

매개 변수

encryptedData
ReadOnlySpan<Byte>

암호 해독할 데이터가 들어 있는 버퍼입니다.

scope
DataProtectionScope

암호화 범위를 지정하는 열거형 값 중 하나입니다.

optionalEntropy
ReadOnlySpan<Byte>

암호화의 복잡성을 높이는 데 사용되는 선택적 추가 버퍼이거나 추가 복잡성 없이 비어 있습니다.

반품

Byte[]

암호화된 데이터를 나타내는 바이트 배열입니다.

예외

암호화에 실패했습니다.

운영 체제에서 이 메서드를 지원하지 않습니다.

시스템에서 데이터 암호를 해독하는 동안 메모리가 부족합니다.

운영 체제가 Windows 않습니다.

적용 대상

Unprotect(ReadOnlySpan<Byte>, DataProtectionScope, Span<Byte>, ReadOnlySpan<Byte>)

Source:
ProtectedData.cs
Source:
ProtectedData.cs
Source:
ProtectedData.cs

지정된 버퍼의 데이터 암호를 해독하고 암호 해독된 데이터를 대상 버퍼에 씁니다.

public static int Unprotect(ReadOnlySpan<byte> encryptedData, System.Security.Cryptography.DataProtectionScope scope, Span<byte> destination, ReadOnlySpan<byte> optionalEntropy = default);
static member Unprotect : ReadOnlySpan<byte> * System.Security.Cryptography.DataProtectionScope * Span<byte> * ReadOnlySpan<byte> -> int
Public Shared Function Unprotect (encryptedData As ReadOnlySpan(Of Byte), scope As DataProtectionScope, destination As Span(Of Byte), Optional optionalEntropy As ReadOnlySpan(Of Byte) = Nothing) As Integer

매개 변수

encryptedData
ReadOnlySpan<Byte>

암호 해독할 데이터가 들어 있는 버퍼입니다.

scope
DataProtectionScope

암호화 범위를 지정하는 열거형 값 중 하나입니다.

destination
Span<Byte>

암호 해독된 데이터를 받을 버퍼입니다.

optionalEntropy
ReadOnlySpan<Byte>

암호화의 복잡성을 높이는 데 사용되는 선택적 추가 버퍼이거나 추가 복잡성 없이 비어 있습니다.

반품

에 기록된 총 바이트 수 destination

예외

버퍼 destination 가 너무 작아서 해독된 데이터를 보관할 수 없습니다.

암호화에 실패했습니다.

운영 체제에서 이 메서드를 지원하지 않습니다.

데이터를 암호화하는 동안 시스템에서 메모리가 부족합니다.

운영 체제가 Windows 않습니다.

적용 대상