RSACryptoServiceProvider.Decrypt 메서드

정의

이전에 암호화된 데이터의 암호를 해독합니다.

오버로드

Decrypt(Byte[], Boolean)

RSA 알고리즘에 따라 데이터를 해독합니다.

Decrypt(Byte[], RSAEncryptionPadding)

지정한 패딩을 사용하여 이전에 RSA 알고리즘으로 암호화된 데이터의 암호를 해독합니다.

Decrypt(Byte[], Boolean)

RSA 알고리즘에 따라 데이터를 해독합니다.

public:
 cli::array <System::Byte> ^ Decrypt(cli::array <System::Byte> ^ rgb, bool fOAEP);
public byte[] Decrypt (byte[] rgb, bool fOAEP);
override this.Decrypt : byte[] * bool -> byte[]
member this.Decrypt : byte[] * bool -> byte[]
Public Function Decrypt (rgb As Byte(), fOAEP As Boolean) As Byte()

매개 변수

rgb
Byte[]

해독할 데이터입니다.

fOAEP
Boolean

OAEP 패딩을 사용하여 직접 RSA 암호 해독을 수행하려면 true이며, 그러지 않고 PKCS#1 v1.5 패딩을 사용하려면 false입니다.

반환

Byte[]

해독된 데이터로, 암호화하기 전의 원래 일반 텍스트입니다.

예외

CSP(암호화 서비스 공급자)를 가져올 수 없습니다.

또는 fOAEP 매개 변수가 true이고 rgb 매개 변수의 길이가 KeySize보다 큰 경우

또는 키가 암호화된 데이터와 일치하지 않습니다. 그러나 예외 표현이 정확하지 않을 수 있습니다. 예를 들어 이 명령을 처리할 만큼 충분한 스토리지 공간이 없습니다.라는 메시지가 표시될 수 있습니다.

rgb이(가) null인 경우

예제

다음 코드 예제에서는 데이터를 암호화하고 암호를 해독합니다.

이 예제에서는 클래스 UnicodeEncodingASCIIEncoding 사용 하지만 대용량 데이터 작업에서 클래스가 더 좋을 수 있습니다. 암호화된 값은 Microsoft SQL Server 데이터 형식으로 nvarchar 저장할 수 있습니다.

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Text;
int main()
{
   try
   {
      
      //Create a UnicodeEncoder to convert between byte array and string.
      ASCIIEncoding^ ByteConverter = gcnew ASCIIEncoding;
      String^ dataString = "Data to Encrypt";
      
      //Create byte arrays to hold original, encrypted, and decrypted data.
      array<Byte>^dataToEncrypt = ByteConverter->GetBytes( dataString );
      array<Byte>^encryptedData;
      array<Byte>^decryptedData;
      
      //Create a new instance of the RSACryptoServiceProvider class 
      // and automatically create a new key-pair.
      RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider;
      
      //Display the origianl data to the console.
      Console::WriteLine( "Original Data: {0}", dataString );
      
      //Encrypt the byte array and specify no OAEP padding.  
      //OAEP padding is only available on Microsoft Windows XP or
      //later.  
      encryptedData = RSAalg->Encrypt( dataToEncrypt, false );
      
      //Display the encrypted data to the console. 
      Console::WriteLine( "Encrypted Data: {0}", ByteConverter->GetString( encryptedData ) );
      
      //Pass the data to ENCRYPT and boolean flag specifying 
      //no OAEP padding.
      decryptedData = RSAalg->Decrypt( encryptedData, false );
      
      //Display the decrypted plaintext to the console. 
      Console::WriteLine( "Decrypted plaintext: {0}", ByteConverter->GetString( decryptedData ) );
   }
   catch ( CryptographicException^ e ) 
   {
      
      //Catch this exception in case the encryption did
      //not succeed.
      Console::WriteLine( e->Message );
   }

}
using System;
using System.Security.Cryptography;
using System.Text;

class RSACSPSample
{
    static void Main()
    {
        try
        {
            //Create a UnicodeEncoder to convert between byte array and string.
            ASCIIEncoding ByteConverter = new ASCIIEncoding();

            string dataString = "Data to Encrypt";

            //Create byte arrays to hold original, encrypted, and decrypted data.
            byte[] dataToEncrypt = ByteConverter.GetBytes(dataString);
            byte[] encryptedData;
            byte[] decryptedData;

            //Create a new instance of the RSACryptoServiceProvider class
            // and automatically create a new key-pair.
            RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider();

            //Display the origianl data to the console.
            Console.WriteLine("Original Data: {0}", dataString);

            //Encrypt the byte array and specify no OAEP padding.
            //OAEP padding is only available on Microsoft Windows XP or
            //later.
            encryptedData = RSAalg.Encrypt(dataToEncrypt, false);

            //Display the encrypted data to the console.
            Console.WriteLine("Encrypted Data: {0}", ByteConverter.GetString(encryptedData));

            //Pass the data to ENCRYPT and boolean flag specifying
            //no OAEP padding.
            decryptedData = RSAalg.Decrypt(encryptedData, false);

            //Display the decrypted plaintext to the console.
            Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData));
        }
        catch(CryptographicException e)
        {
            //Catch this exception in case the encryption did
            //not succeed.
            Console.WriteLine(e.Message);
        }
    }
}
Imports System.Security.Cryptography
Imports System.Text

Module RSACSPExample

    Sub Main()
        Try
            'Create a UnicodeEncoder to convert between byte array and string.
            Dim ByteConverter As New ASCIIEncoding

            Dim dataString As String = "Data to Encrypt"

            'Create byte arrays to hold original, encrypted, and decrypted data.
            Dim dataToEncrypt As Byte() = ByteConverter.GetBytes(dataString)
            Dim encryptedData() As Byte
            Dim decryptedData() As Byte

            'Create a new instance of the RSACryptoServiceProvider class 
            ' and automatically create a new key-pair.
            Dim RSAalg As New RSACryptoServiceProvider

            'Display the origianl data to the console.
            Console.WriteLine("Original Data: {0}", dataString)

            'Encrypt the byte array and specify no OAEP padding.  
            'OAEP padding is only available on Microsoft Windows XP or
            'later.  
            encryptedData = RSAalg.Encrypt(dataToEncrypt, False)

            'Display the encrypted data to the console. 
            Console.WriteLine("Encrypted Data: {0}", ByteConverter.GetString(encryptedData))

            'Pass the data to ENCRYPT and boolean flag specifying 
            'no OAEP padding.
            decryptedData = RSAalg.Decrypt(encryptedData, False)

            'Display the decrypted plaintext to the console. 
            Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData))
        Catch e As CryptographicException
            'Catch this exception in case the encryption did
            'not succeed.
            Console.WriteLine(e.Message)
        End Try
    End Sub 

End Module

설명

이 메서드를 사용하여 암호 해독을 위해 데이터를 암호화하는 데 사용합니다 Encrypt .

추가 정보

적용 대상

Decrypt(Byte[], RSAEncryptionPadding)

지정한 패딩을 사용하여 이전에 RSA 알고리즘으로 암호화된 데이터의 암호를 해독합니다.

public:
 override cli::array <System::Byte> ^ Decrypt(cli::array <System::Byte> ^ data, System::Security::Cryptography::RSAEncryptionPadding ^ padding);
public override byte[] Decrypt (byte[] data, System.Security.Cryptography.RSAEncryptionPadding padding);
override this.Decrypt : byte[] * System.Security.Cryptography.RSAEncryptionPadding -> byte[]
Public Overrides Function Decrypt (data As Byte(), padding As RSAEncryptionPadding) As Byte()

매개 변수

data
Byte[]

해독할 데이터입니다.

padding
RSAEncryptionPadding

패딩입니다.

반환

Byte[]

암호 해독된 데이터입니다.

예외

data이(가) null인 경우

또는 padding이(가) null인 경우

패딩 모드가 지원되지 않는 경우

설명

padding 은 (0) 중 하나 RSAEncryptionPadding.Pkcs1 또는 RSAEncryptionPadding.OaepSHA1.이어야 합니다.

적용 대상