RSACryptoServiceProvider.Decrypt メソッド

定義

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

オーバーロード

Decrypt(Byte[], Boolean)

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

Decrypt(Byte[], RSAEncryptionPadding)

指定された埋め込みを使用した RSA アルゴリズムで暗号化されたデータを復号化します。

Decrypt(Byte[], Boolean)

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

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

C#
public byte[] Decrypt(byte[] rgb, bool fOAEP);

パラメーター

rgb
Byte[]

復号化するデータ。

fOAEP
Boolean

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

戻り値

Byte[]

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

例外

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

- または -

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

- または -

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

rgbnull です。

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

この例では、 クラスを ASCIIEncoding 使用します。ただし、 UnicodeEncoding 大規模なデータ操作では、 クラスが好ましい場合があります。 暗号化された値は、Microsoft SQL Server のデータ型として nvarchar 保存できます。

C#
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);
        }
    }
}

注釈

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

こちらもご覧ください

適用対象

.NET 10 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Decrypt(Byte[], RSAEncryptionPadding)

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

指定された埋め込みを使用した RSA アルゴリズムで暗号化されたデータを復号化します。

C#
public override byte[] Decrypt(byte[] data, System.Security.Cryptography.RSAEncryptionPadding padding);

パラメーター

data
Byte[]

復号化するデータ。

padding
RSAEncryptionPadding

パディング。

戻り値

Byte[]

復号化されるデータ。

例外

datanull です。

または

paddingnullです。

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

注釈

paddingは または RSAEncryptionPadding.OaepSHA1であるRSAEncryptionPadding.Pkcs1必要があります。

適用対象

.NET 10 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1