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

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

RSACryptoServiceProvider.Encrypt メソッド

RSA アルゴリズムデータ暗号化ます。

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

Public Function Encrypt ( _
    rgb As Byte(), _
    fOAEP As Boolean _
) As Byte()
Dim instance As RSACryptoServiceProvider
Dim rgb As Byte()
Dim fOAEP As Boolean
Dim returnValue As Byte()

returnValue = instance.Encrypt(rgb, fOAEP)
public byte[] Encrypt (
    byte[] rgb,
    bool fOAEP
)
public:
array<unsigned char>^ Encrypt (
    array<unsigned char>^ rgb, 
    bool fOAEP
)
public byte[] Encrypt (
    byte[] rgb, 
    boolean fOAEP
)
public function Encrypt (
    rgb : byte[], 
    fOAEP : boolean
) : byte[]

パラメータ

rgb

暗号化されるデータ

fOAEP

Microsoft Windows XP 以降実行するコンピュータだけで使用できる OAEP パディング使用して直接 RSA 暗号化を実行する場合trueそれ以外場合は、PKCS#1 v1.5 パディング使用することを表す false

戻り値
暗号化されたデータ

例外例外
例外種類条件

CryptographicException

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

または

rgb パラメータ長さ許可され最大長を超えてます。

または

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

解説解説
使用例使用例

RSACryptoServiceProvider オブジェクトを (相手から送信された) 公開キーの値に初期化し、RijndaelManaged アルゴリズム使用してセッション キー生成してRSACryptoServiceProvider オブジェクト使用してセッション キー暗号化するコード例次に示しますこの方式を使用すると、セッション キーRSA 秘密キー所有者返送し双方セッション キー使用して暗号化されたデータ交換できます

Imports System
Imports System.Security.Cryptography

Class RSACSPSample

    Shared Sub Main()
        Try
            'initialze the byte arrays to the public key information.
            Dim PublicKey As Byte()
 = {214, 46, 220, 83, 160, 73, 40, 39, 201, 155, 19, 202, 3, 11, 191, 178, 56, 74,
 90, 36, 248, 103, 18, 144, 170, 163, 145, 87, 54, 61, 34, 220, 222, 207, 137, 149, 173, 14, 92, 120, 206, 222, 158, 28, 40, 24, 30, 16, 175, 108, 128, 35, 230, 118, 40, 121,
 113, 125, 216, 130, 11, 24, 90, 48, 194, 240, 105, 44, 76, 34, 57, 249, 228, 125, 80, 38, 9, 136, 29, 117, 207, 139, 168, 181, 85, 137, 126, 10, 126, 242, 120, 247, 121, 8, 100, 12, 201, 171, 38, 226, 193, 180, 190, 117, 177, 87, 143, 242, 213, 11, 44, 180, 113, 93, 106, 99, 179, 68, 175, 211, 164, 116, 64, 148, 226, 254, 172, 147}

            Dim Exponent As Byte()
 = {1, 0, 1}

            'Values to store encrypted symmetric keys.
            Dim EncryptedSymmetricKey() As
 Byte
            Dim EncryptedSymmetricIV() As Byte

            'Create a new instance of RSACryptoServiceProvider.
            Dim RSA As New
 RSACryptoServiceProvider()

            'Create a new instance of RSAParameters.
            Dim RSAKeyInfo As New
 RSAParameters()

            'Set RSAKeyInfo to the public key values. 
            RSAKeyInfo.Modulus = PublicKey
            RSAKeyInfo.Exponent = Exponent

            'Import key parameters into RSA.
            RSA.ImportParameters(RSAKeyInfo)

            'Create a new instance of the RijndaelManaged class.
            Dim RM As New
 RijndaelManaged()

            'Encrypt the symmetric key and IV.
            EncryptedSymmetricKey = RSA.Encrypt(RM.Key, False)
            EncryptedSymmetricIV = RSA.Encrypt(RM.IV, False)

            Console.WriteLine("RijndaelManaged Key and IV have
 been encrypted with RSACryptoServiceProvider.")

            'Catch and display a CryptographicException  
            'to the console.
        Catch e As CryptographicException
            Console.WriteLine(e.Message)
        End Try
    End Sub
End Class
using System;
using System.Security.Cryptography;

class RSACSPSample
{

    static void Main()
    {
        try
        {        //initialze the byte arrays to the public key information.
            byte[] PublicKey = {214,46,220,83,160,73,40,39,201,155,19,202,3,11,191
,178,56,
                                   74,90,36,248,103,18,144,170,163,145,87,54,61,34
,220,222,
                                   207,137,149,173,14,92,120,206,222,158,28,40,24
,30,16,175,
                                   108,128,35,230,118,40,121,113,125,216,130,11,24
,90,48,194,
                                   240,105,44,76,34,57,249,228,125,80,38,9,136,29
,117,207,139,
                                   168,181,85,137,126,10,126,242,120,247,121,8,100
,12,201,171,
                                   38,226,193,180,190,117,177,87,143,242,213,11,44
,180,113,93,
                                   106,99,179,68,175,211,164,116,64,148,226,254,172
,147};

            byte[] Exponent = {1,0,1};
      
            //Values to store encrypted symmetric keys.
            byte[] EncryptedSymmetricKey;
            byte[] EncryptedSymmetricIV;

            //Create a new instance of RSACryptoServiceProvider.
            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

            //Create a new instance of RSAParameters.
            RSAParameters RSAKeyInfo = new RSAParameters();

            //Set RSAKeyInfo to the public key values. 
            RSAKeyInfo.Modulus = PublicKey;
            RSAKeyInfo.Exponent = Exponent;

            //Import key parameters into RSA.
            RSA.ImportParameters(RSAKeyInfo);

            //Create a new instance of the RijndaelManaged class.
            RijndaelManaged RM = new RijndaelManaged();

            //Encrypt the symmetric key and IV.
            EncryptedSymmetricKey = RSA.Encrypt(RM.Key, false);
            EncryptedSymmetricIV = RSA.Encrypt(RM.IV, false);

            Console.WriteLine("RijndaelManaged Key and IV have been encrypted
 with RSACryptoServiceProvider."); 
        
        }
        //Catch and display a CryptographicException  
        //to the console.
        catch(CryptographicException e)
        {
            Console.WriteLine(e.Message);
        }
    }
}
#using <System.dll>

using namespace System;
using namespace System::Security::Cryptography;
int main()
{
   try
   {
      
      //initialze the Byte arrays to the public key information.
      array<Byte>^PublicKey = {214,46,220,83,160,73,40,39,201,155,19,202,3
,11,191,178,56,74,90,36,248,103,18,144,170,163,145,87,54,61,34,220,222,207,137,149
,173,14,92,120,206,222,158,28,40,24,30,16,175,108,128,35,230,118,40,121,113,125,216,130,11,24,90,48,194,240,105,44,76,34,57,249,228,125,80,38,9,136,29,117,207,139
,168,181,85,137,126,10,126,242,120,247,121,8,100,12,201,171,38,226,193,180,190,117,177,87,143,242,213,11,44,180,113,93,106,99,179,68,175,211,164,116,64,148,226,254,172,147};
      array<Byte>^Exponent = {1,0,1};
      
      //Values to store encrypted symmetric keys.
      array<Byte>^EncryptedSymmetricKey;
      array<Byte>^EncryptedSymmetricIV;
      
      //Create a new instance of RSACryptoServiceProvider.
      RSACryptoServiceProvider^ RSA = gcnew RSACryptoServiceProvider;
      
      //Create a new instance of RSAParameters.
      RSAParameters RSAKeyInfo;
      
      //Set RSAKeyInfo to the public key values. 
      RSAKeyInfo.Modulus = PublicKey;
      RSAKeyInfo.Exponent = Exponent;
      
      //Import key parameters into RSA.
      RSA->ImportParameters( RSAKeyInfo );
      
      //Create a new instance of the RijndaelManaged class.
      RijndaelManaged^ RM = gcnew RijndaelManaged;
      
      //Encrypt the symmetric key and IV.
      EncryptedSymmetricKey = RSA->Encrypt( RM->Key, false
 );
      EncryptedSymmetricIV = RSA->Encrypt( RM->IV, false
 );
      Console::WriteLine( "RijndaelManaged Key and IV have been encrypted with
 RSACryptoServiceProvider." );
   }
   catch ( CryptographicException^ e ) 
   {
      
      //Catch and display a CryptographicException  
      //to the console.
      Console::WriteLine( e->Message );
   }

}

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

class RSACSPSample
{
    public static void main(String[]
 args)
    {
        try {
            // initialze the byte arrays to the public key information.
            ubyte publicKey[] =  {214, 46, 220, 83, 160, 73, 40, 39, 201, 
                    155, 19, 202, 3, 11, 191, 178, 56, 74, 90, 36, 248, 
                    103, 18, 144, 170, 163, 145, 87, 54, 61, 34, 220, 
                    222, 207, 137, 149, 173, 14, 92, 120, 206, 222, 
                    158, 28, 40, 24, 30, 16, 175, 108, 128, 35, 
                    230, 118, 40, 121, 113, 125, 216, 130, 11, 
                    24, 90, 48, 194, 240, 105, 44, 76, 34, 57, 
                    249, 228, 125, 80, 38, 9, 136, 29, 117, 
                    207, 139, 168, 181, 85, 137, 126, 10, 126, 242, 120, 
                    247, 121, 8, 100, 12, 201, 171, 38, 226, 193, 180, 
                    190, 117, 177, 87, 143, 242, 213, 11, 44, 180, 113, 
                    93, 106, 99, 179, 68, 175, 211, 164, 116, 64, 148, 
                    226, 254, 172, 147};
            
            ubyte exponent[] =  {1, 0, 1};
            
            // Values to store encrypted symmetric keys.
            ubyte encryptedSymmetricKey[];
            ubyte encryptedSymmetricIV[];
            
            // Create a new instance of RSACryptoServiceProvider.
            RSACryptoServiceProvider rsa =  new RSACryptoServiceProvider();
            
            // Create a new instance of RSAParameters.
            RSAParameters rsaKeyInfo =  new RSAParameters();
            
            // Set rsaKeyInfo to the public key values. 
            rsaKeyInfo.Modulus = publicKey;
            rsaKeyInfo.Exponent = exponent;
            
            // Import key parameters into rsa.
            rsa.ImportParameters(rsaKeyInfo);
            
            // Create a new instance of the RijndaelManaged class.
            RijndaelManaged rm =  new RijndaelManaged();
            
            // Encrypt the symmetric key and IV.
            encryptedSymmetricKey = rsa.Encrypt(rm.get_Key(), false);
            encryptedSymmetricIV = rsa.Encrypt(rm.get_IV(), false);
            
            Console.WriteLine("RijndaelManaged Key and IV have been " 
                + "encrypted with RSACryptoServiceProvider.");
        } 
        // Catch and display a CryptographicException  
        // to the console.
        catch (CryptographicException e) {
            Console.WriteLine(e.get_Message());
        }
    } //main
} //RSACSPSample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RSACryptoServiceProvider クラス
RSACryptoServiceProvider メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス


このページでは「.NET Framework クラス ライブラリ リファレンス」からRSACryptoServiceProvider.Encrypt メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からRSACryptoServiceProvider.Encrypt メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からRSACryptoServiceProvider.Encrypt メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

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

   

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



RSACryptoServiceProvider.Encrypt メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS