Partager via


RSACryptoServiceProvider.Decrypt Méthode

Définition

Déchiffre les données précédemment chiffrées.

Surcharges

Nom Description
Decrypt(Byte[], Boolean)
Obsolète.

Déchiffre les données avec l’algorithme RSA .

Decrypt(Byte[], RSAEncryptionPadding)

Déchiffre les données précédemment chiffrées avec l’algorithme à l’aide RSA du remplissage spécifié.

Decrypt(Byte[], Boolean)

Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs

Attention

RSACryptoServiceProvider.Encrypt and RSACryptoServiceProvider.Decrypt methods that take a Boolean are obsolete. Use the overload that accepts RSAEncryptionPadding instead.

Déchiffre les données avec l’algorithme RSA .

public:
 cli::array <System::Byte> ^ Decrypt(cli::array <System::Byte> ^ rgb, bool fOAEP);
public byte[] Decrypt(byte[] rgb, bool fOAEP);
[System.Obsolete("RSACryptoServiceProvider.Encrypt and RSACryptoServiceProvider.Decrypt methods that take a Boolean are obsolete. Use the overload that accepts RSAEncryptionPadding instead.", DiagnosticId="SYSLIB0064", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public byte[] Decrypt(byte[] rgb, bool fOAEP);
override this.Decrypt : byte[] * bool -> byte[]
[<System.Obsolete("RSACryptoServiceProvider.Encrypt and RSACryptoServiceProvider.Decrypt methods that take a Boolean are obsolete. Use the overload that accepts RSAEncryptionPadding instead.", DiagnosticId="SYSLIB0064", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
override this.Decrypt : byte[] * bool -> byte[]
member this.Decrypt : byte[] * bool -> byte[]
Public Function Decrypt (rgb As Byte(), fOAEP As Boolean) As Byte()

Paramètres

rgb
Byte[]

Données à déchiffrer.

fOAEP
Boolean

true pour effectuer un déchiffrement direct RSA à l’aide du remplissage OAEP ; sinon, false pour utiliser le remplissage PKCS#1 v1.5.

Retours

Byte[]

Données déchiffrées, qui est le texte brut d’origine avant le chiffrement.

Attributs

Exceptions

Le fournisseur de services de chiffrement (CSP) ne peut pas être acquis.

- ou -

Le fOAEP paramètre est true et la longueur du rgb paramètre est supérieure à KeySize.

- ou -

La clé ne correspond pas aux données chiffrées. Toutefois, la formulation de l’exception peut ne pas être exacte. Par exemple, il peut dire Not enough storage is available to process this command.

rgb a la valeur null.

Exemples

L’exemple de code suivant chiffre et déchiffre les données.

Cet exemple utilise la ASCIIEncoding classe ; toutefois, la UnicodeEncoding classe peut être préférable dans les opérations de données volumineuses. La valeur chiffrée peut être enregistrée en tant que type de données nvarchar dans 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

Remarques

Permet Encrypt de chiffrer les données pour le déchiffrement avec cette méthode.

Voir aussi

S’applique à

Decrypt(Byte[], RSAEncryptionPadding)

Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs

Déchiffre les données précédemment chiffrées avec l’algorithme à l’aide RSA du remplissage spécifié.

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ètres

data
Byte[]

Données à déchiffrer.

padding
RSAEncryptionPadding

Le remplissage.

Retours

Byte[]

Données déchiffrées.

Exceptions

data a la valeur null.

- ou -

padding a la valeur null.

Le mode de remplissage n’est pas pris en charge.

Remarques

padding doit être RSAEncryptionPadding.Pkcs1 ou RSAEncryptionPadding.OaepSHA1.

S’applique à