RSACryptoServiceProvider.Decrypt メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > RSACryptoServiceProvider.Decrypt メソッドの意味・解説 

RSACryptoServiceProvider.Decrypt メソッド

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

名前空間: System.Security.Cryptography
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外の種類条件

CryptographicException

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

または

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

または

fOAEP パラメータが true で、OAEP がサポートされていません。

解説解説

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

使用例使用例

データの暗号化と復号化を行うコード例を次に示します。

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

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

}

import System.*;
import System.Security.Cryptography.*;
import System.Text.*;

class RSACSPSample
{
    public static void main(String[]
 args)
    {
        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.
            ubyte dataToEncrypt[] = byteConverter.GetBytes(dataString);
            ubyte encryptedData[];
            ubyte 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.get_Message());
        }
    } //main
} //RSACSPSample
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RSACryptoServiceProvider クラス
RSACryptoServiceProvider メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

RSACryptoServiceProvider.Decrypt メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



RSACryptoServiceProvider.Decrypt メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS