RSACryptoServiceProvider.Decrypt Methode

Definition

Entschlüsselt Daten, die zuvor verschlüsselt wurden.Decrypts data that was previously encrypted.

Überlädt

Decrypt(Byte[], Boolean)

Verschlüsselt Daten mit dem RSA-Algorithmus.Decrypts data with the RSA algorithm.

Decrypt(Byte[], RSAEncryptionPadding)

Entschlüsselt zuvor mit dem RSA-Algorithmus verschlüsselte Daten unter Verwendung des angegebene Paddingmodus.Decrypts data that was previously encrypted with the RSA algorithm by using the specified padding.

Decrypt(Byte[], Boolean)

Verschlüsselt Daten mit dem RSA-Algorithmus.Decrypts data with the RSA algorithm.

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()

Parameter

rgb
Byte[]

Die zu entschlüsselnden Daten.The data to be decrypted.

fOAEP
Boolean

true, um direkte RSA-Entschlüsselung mit OAEP-Padding (Auffüllung) auszuführen, andernfalls false, um Padding gemäß PKCS#1 v1.5 zu verwenden.true to perform direct RSA decryption using OAEP padding; otherwise, false to use PKCS#1 v1.5 padding.

Gibt zurück

Byte[]

Die entschlüsselten Daten, d. h. der ursprüngliche Klartext vor der Verschlüsselung.The decrypted data, which is the original plain text before encryption.

Ausnahmen

Der Kryptografiedienstanbieter (Cryptographic Service Provider, CSP) kann nicht abgerufen werden.The cryptographic service provider (CSP) cannot be acquired.

- oder --or- Der fOAEP-Parameter ist true, und die Länge des rgb-Parameters ist größer als KeySize.The fOAEP parameter is true and the length of the rgb parameter is greater than KeySize.

- oder --or- Der Schlüssel stimmt nicht mit den verschlüsselten Daten überein.The key does not match the encrypted data. Allerdings ist der Wortlaut der Ausnahme möglicherweise nicht präzise.However, the exception wording may not be accurate. Die Meldung kann beispielsweise Zum Verarbeiten des Befehls ist nicht genügend Speicherplatz verfügbar lauten.For example, it may say Not enough storage is available to process this command.

rgb ist null.rgb is null.

Beispiele

Im folgenden Codebeispiel werden Daten verschlüsselt und entschlüsselt.The following code example encrypts and decrypts data.

In diesem Beispiel wird die- ASCIIEncoding Klasse verwendet. die- UnicodeEncoding Klasse kann jedoch bei großen Daten Vorgängen bevorzugt werden.This example uses the ASCIIEncoding class; however, the UnicodeEncoding class may be preferable in large data operations. Der verschlüsselte Wert kann nvarchar in Microsoft SQL Server als Datentyp gespeichert werden.The encrypted value can be saved as an nvarchar data type in Microsoft SQL Server.

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

Hinweise

Verwenden Encrypt Sie, um Daten für die Entschlüsselung mit dieser Methode zu verschlüsseln.Use Encrypt to encrypt data for decryption with this method.

Weitere Informationen

Gilt für:

Decrypt(Byte[], RSAEncryptionPadding)

Entschlüsselt zuvor mit dem RSA-Algorithmus verschlüsselte Daten unter Verwendung des angegebene Paddingmodus.Decrypts data that was previously encrypted with the RSA algorithm by using the specified padding.

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()

Parameter

data
Byte[]

Die zu entschlüsselnden Daten.The data to decrypt.

padding
RSAEncryptionPadding

Der Paddingmodus.The padding.

Gibt zurück

Byte[]

Die entschlüsselten Daten.The decrypted data.

Ausnahmen

data ist null.data is null.

- oder --or- padding ist null.padding is null.

Der Paddingmodus wird nicht unterstützt.The padding mode is not supported.

Hinweise

padding muss entweder RSAEncryptionPadding.Pkcs1 oder sein RSAEncryptionPadding.OaepSHA1 .padding must be either RSAEncryptionPadding.Pkcs1 or RSAEncryptionPadding.OaepSHA1.

Gilt für: