RSACryptoServiceProvider.Decrypt Metódus

Definíció

A korábban titkosított adatok visszafejtése.

Túlterhelések

Name Description
Decrypt(Byte[], Boolean)

Adatok visszafejtése az RSA algoritmussal.

Decrypt(Byte[], RSAEncryptionPadding)

A korábban az RSA algoritmussal titkosított adatok visszafejtése a megadott kitöltéssel.

Decrypt(Byte[], Boolean)

Adatok visszafejtése az RSA algoritmussal.

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

Paraméterek

rgb
Byte[]

A visszafejtendő adatok.

fOAEP
Boolean

true közvetlen RSA visszafejtéshez OAEP-padding használatával; false ellenkező esetben pKCS#1 v1.5-ös padding használata.

Válaszok

Byte[]

A visszafejtött adatok, amelyek a titkosítás előtt az eredeti egyszerű szöveg.

Kivételek

A titkosítási szolgáltató (CSP) nem szerezhető be.

-vagy-

A fOAEP paraméter értéke true és a paraméter hossza rgb nagyobb, mint KeySize.

-vagy-

A kulcs nem egyezik a titkosított adatokkal. Előfordulhat azonban, hogy a kivétel szövege nem pontos. Például azt mondhatja, hogy Not enough storage is available to process this command.

rgb az null.

Példák

Az alábbi példakód titkosítja és visszafejti az adatokat.

Ez a példa az osztályt ASCIIEncoding használja, azonban a nagy adatműveletek esetén előnyösebb UnicodeEncoding lehet az osztály. A titkosított érték nvarchar adattípusként menthető Microsoft SQL Server.

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

Megjegyzések

Ezzel Encrypt a módszerrel titkosíthatja az adatokat visszafejtéshez.

Lásd még

A következőre érvényes:

Decrypt(Byte[], RSAEncryptionPadding)

A korábban az RSA algoritmussal titkosított adatok visszafejtése a megadott kitöltéssel.

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

Paraméterek

data
Byte[]

A visszafejtendő adatok.

padding
RSAEncryptionPadding

A padding.

Válaszok

Byte[]

A visszafejtött adatok.

Kivételek

data az null.

-vagy-

padding az null.

A kitöltési mód nem támogatott.

Megjegyzések

padding vagy RSAEncryptionPadding.Pkcs1 vagy RSAEncryptionPadding.OaepSHA1.

A következőre érvényes: