次の方法で共有


RSACryptoServiceProvider.Decrypt メソッド

定義

以前に暗号化されたデータを復号化します。

オーバーロード

名前 説明
Decrypt(Byte[], Boolean)
古い.

RSA アルゴリズムを使用してデータを復号化します。

Decrypt(Byte[], RSAEncryptionPadding)

指定したパディングを使用して、 RSA アルゴリズムで以前に暗号化されたデータを復号化します。

Decrypt(Byte[], Boolean)

ソース:
RSACryptoServiceProvider.Unix.cs
ソース:
RSACryptoServiceProvider.Unix.cs
ソース:
RSACryptoServiceProvider.Unix.cs
ソース:
RSACryptoServiceProvider.Unix.cs
ソース:
RSACryptoServiceProvider.Unix.cs

注意事項

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

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

パラメーター

rgb
Byte[]

復号化するデータ。

fOAEP
Boolean

true OAEP パディングを使用して直接 RSA 復号化を実行する場合は a0/>。それ以外の場合は、PKCS#1 v1.5 パディングを使用 false

返品

Byte[]

暗号化解除されたデータ。暗号化前の元のプレーン テキストです。

属性

例外

暗号化サービス プロバイダー (CSP) を取得できません。

-又は-

fOAEP パラメーターがtrueされ、rgb パラメーターの長さがKeySizeを超えています。

-又は-

キーが暗号化されたデータと一致しません。 ただし、例外文言は正確でない場合があります。 たとえば、 Not enough storage is available to process this commandと言う場合があります。

rgbnullです。

次のコード例では、データの暗号化と暗号化解除を行います。

この例では、 ASCIIEncoding クラスを使用します。ただし、大規模なデータ操作では、 UnicodeEncoding クラスが適している場合があります。 暗号化された値は、nvarchar データ型として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

注釈

Encryptを使用して、このメソッドを使用して復号化するデータを暗号化します。

こちらもご覧ください

適用対象

Decrypt(Byte[], RSAEncryptionPadding)

ソース:
RSACryptoServiceProvider.Unix.cs
ソース:
RSACryptoServiceProvider.Unix.cs
ソース:
RSACryptoServiceProvider.Unix.cs
ソース:
RSACryptoServiceProvider.Unix.cs
ソース:
RSACryptoServiceProvider.Unix.cs

指定したパディングを使用して、 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[]

復号化されたデータ。

例外

datanullです。

-又は-

paddingnullです。

パディング モードはサポートされていません。

注釈

padding は、RSAEncryptionPadding.Pkcs1 または RSAEncryptionPadding.OaepSHA1 のいずれかである必要があります。

適用対象