RSACryptoServiceProvider.Decrypt メソッド

定義

以前に暗号化されたデータを復号化します。Decrypts data that was previously encrypted.

オーバーロード

Decrypt(Byte[], Boolean)

RSA アルゴリズムでデータの暗号化を解除します。Decrypts data with the RSA algorithm.

Decrypt(Byte[], RSAEncryptionPadding)

指定された埋め込みを使用した RSA アルゴリズムで暗号化されたデータを復号化します。Decrypts data that was previously encrypted with the RSA algorithm by using the specified padding.

Decrypt(Byte[], Boolean)

RSA アルゴリズムでデータの暗号化を解除します。Decrypts data with the RSA algorithm.

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[]
Public Function Decrypt (rgb As Byte(), fOAEP As Boolean) As Byte()

パラメーター

rgb
Byte[]

復号化するデータ。The data to be decrypted.

fOAEP
Boolean

Microsoft Windows XP 以降を実行するコンピューターだけで使用できる OAEP パディングを使用して、直接 RSA 復号化を実行する場合は true。それ以外の場合は、PKCS#1 v1.5 パディングを使用することを表す falsetrue to perform direct RSA decryption using OAEP padding (only available on a computer running Microsoft Windows XP or later); otherwise, false to use PKCS#1 v1.5 padding.

戻り値

Byte[]

暗号化を解除されたデータ。これは、暗号化前の元のプレーンテキストです。The decrypted data, which is the original plain text before encryption.

例外

暗号化サービス プロバイダー (CSP) を取得できません。The cryptographic service provider (CSP) cannot be acquired.

- または --or- fOAEP パラメーターが true であり、rgb パラメーターの長さが KeySize を超える値です。The fOAEP parameter is true and the length of the rgb parameter is greater than KeySize.

または-or- fOAEP パラメーターが true で、OAEP がサポートされていません。The fOAEP parameter is true and OAEP is not supported.

- または --or- キーが、暗号化されたデータと一致しません。The key does not match the encrypted data. ただし、例外の表現は正確でない場合があります。However, the exception wording may not be accurate. たとえば、このコマンドを処理するのに必要な記憶域をサーバーで確保できませんと表示される場合があります。For example, it may say Not enough storage is available to process this command.

rgbnullです。rgb is null.

次のコード例では、データの暗号化と復号化を行います。The following code example encrypts and decrypts data.

この例ではASCIIEncodingクラスを使用しますUnicodeEncodingが、大規模なデータ操作ではクラスが適している場合があります。This example uses the ASCIIEncoding class; however, the UnicodeEncoding class may be preferable in large data operations. 暗号化された値は、Microsoft SQL Server nvarchar 2005 でデータ型として保存できます。The encrypted value can be saved as an nvarchar data type in Microsoft SQL Server 2005.

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Text;
int main()
{
   try
   {
      
      //Create a UnicodeEncoder to convert between byte array and string.
      ASCIIEncoding^ ByteConverter = gcnew ASCIIEncoding;
      String^ dataString = "Data to Encrypt";
      
      //Create byte arrays to hold original, encrypted, and decrypted data.
      array<Byte>^dataToEncrypt = ByteConverter->GetBytes( dataString );
      array<Byte>^encryptedData;
      array<Byte>^decryptedData;
      
      //Create a new instance of the RSACryptoServiceProvider class 
      // and automatically create a new key-pair.
      RSACryptoServiceProvider^ RSAalg = gcnew 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 );
   }

}

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メソッドを使用して復号化するデータを暗号化するには、を使用します。Use Encrypt to encrypt data for decryption with this method.

セキュリティ

KeyContainerPermissionAccessEntryCollection
暗号化を解除する権限。for permission to decrypt. セキュリティアクション: DemandSecurity action: Demand. 関連付けられた列挙型:DecryptAssociated enumeration: Decrypt

こちらもご覧ください

Decrypt(Byte[], RSAEncryptionPadding)

指定された埋め込みを使用した RSA アルゴリズムで暗号化されたデータを復号化します。Decrypts data that was previously encrypted with the RSA algorithm by using the specified padding.

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[]

復号化するデータ。The data to decrypt.

padding
RSAEncryptionPadding

パディング。The padding.

戻り値

Byte[]

復号化されるデータ。The decrypted data.

例外

datanull です。data is null.

- または --or- paddingnull です。padding is null.

そのパディング モードはサポートされていません。The padding mode is not supported.

注釈

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

適用対象