RSACryptoServiceProvider.Decrypt Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Descifra los datos que se cifraron anteriormente.
Sobrecargas
| Nombre | Description |
|---|---|
| Decrypt(Byte[], Boolean) |
Obsoletos.
Descifra los datos con el RSA algoritmo . |
| Decrypt(Byte[], RSAEncryptionPadding) |
Descifra los datos que se cifraron anteriormente con el RSA algoritmo mediante el relleno especificado. |
Decrypt(Byte[], Boolean)
Precaución
RSACryptoServiceProvider.Encrypt and RSACryptoServiceProvider.Decrypt methods that take a Boolean are obsolete. Use the overload that accepts RSAEncryptionPadding instead.
Descifra los datos con el RSA algoritmo .
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()
Parámetros
- rgb
- Byte[]
Datos que se van a descifrar.
- fOAEP
- Boolean
true para realizar el descifrado directo RSA mediante el relleno OAEP; de lo contrario, false para usar el relleno PKCS#1 v1.5.
Devoluciones
Los datos descifrados, que es el texto sin formato original antes del cifrado.
- Atributos
Excepciones
No se puede adquirir el proveedor de servicios criptográficos (CSP).
O bien
El fOAEP parámetro es true y la longitud del rgb parámetro es mayor que KeySize.
O bien
La clave no coincide con los datos cifrados. Sin embargo, es posible que la redacción de la excepción no sea precisa. Por ejemplo, puede decir Not enough storage is available to process this command.
rgb es null.
Ejemplos
En el ejemplo de código siguiente se cifran y descifran los datos.
En este ejemplo se usa la ASCIIEncoding clase ; sin embargo, la UnicodeEncoding clase puede ser preferible en operaciones de datos grandes. El valor cifrado se puede guardar como un tipo de datos />
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
Comentarios
Use Encrypt para cifrar los datos para el descifrado con este método.
Consulte también
Se aplica a
Decrypt(Byte[], RSAEncryptionPadding)
Descifra los datos que se cifraron anteriormente con el RSA algoritmo mediante el relleno especificado.
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()
Parámetros
- data
- Byte[]
Datos que se van a descifrar.
- padding
- RSAEncryptionPadding
Relleno.
Devoluciones
Datos descifrados.
Excepciones
No se admite el modo de relleno.
Comentarios
padding debe ser RSAEncryptionPadding.Pkcs1 o RSAEncryptionPadding.OaepSHA1.