RC2CryptoServiceProvider コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > RC2CryptoServiceProvider コンストラクタの意味・解説 

RC2CryptoServiceProvider コンストラクタ

RC2CryptoServiceProvider クラス新しインスタンス初期化します。

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

Dim instance As New RC2CryptoServiceProvider
public RC2CryptoServiceProvider ()
public:
RC2CryptoServiceProvider ()
public RC2CryptoServiceProvider ()
public function RC2CryptoServiceProvider ()
例外例外
例外種類条件

CryptographicException

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

InvalidOperationException

互換性のない FIPS アルゴリズムが見つかりました

使用例使用例

次のコード例は、文字列暗号化した後で復号化ます。

Imports System
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography



Module MyMainModule

    Sub Main()

        ' Create a new instance of the RC2CryptoServiceProvider class
        ' and automatically generate a Key and IV.
        Dim rc2CSP As New
 RC2CryptoServiceProvider()

        Console.WriteLine("Effective key size is {0} bits.",
 rc2CSP.EffectiveKeySize)

        ' Get the key and IV.
        Dim key As Byte()
 = rc2CSP.Key
        Dim IV As Byte()
 = rc2CSP.IV

        ' Get an encryptor.
        Dim encryptor As ICryptoTransform =
 rc2CSP.CreateEncryptor(key, IV)

        ' Encrypt the data as an array of encrypted bytes in memory.
        Dim msEncrypt As New
 MemoryStream()
        Dim csEncrypt As New
 CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)

        ' Convert the data to a byte array.
        Dim original As String
 = "Here is some data to encrypt."
        Dim toEncrypt As Byte()
 = Encoding.ASCII.GetBytes(original)

        ' Write all data to the crypto stream and flush it.
        csEncrypt.Write(toEncrypt, 0, toEncrypt.Length)
        csEncrypt.FlushFinalBlock()

        ' Get the encrypted array of bytes.
        Dim encrypted As Byte()
 = msEncrypt.ToArray()

        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' This is where the data could be transmitted or saved.    
      
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        'Get a decryptor that uses the same key and IV as the encryptor.
        Dim decryptor As ICryptoTransform =
 rc2CSP.CreateDecryptor(key, IV)

        ' Now decrypt the previously encrypted message using the decryptor
        ' obtained in the above step.
        Dim msDecrypt As New
 MemoryStream(encrypted)
        Dim csDecrypt As New
 CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)

        Dim fromEncrypt(toEncrypt.Length) As
 Byte

        ' Read the data out of the crypto stream.
        csDecrypt.Read(fromEncrypt, 0, toEncrypt.Length)

        ' Convert the byte array back into a string.
        Dim roundtrip As String
 = Encoding.ASCII.GetString(fromEncrypt)

        ' Display the original data and the decrypted data.
        Console.WriteLine("Original:   {0}", original)
        Console.WriteLine("Round Trip: {0}", roundtrip)

        Console.ReadLine()

    End Sub
End Module
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;

namespace RC2CryptoServiceProvider_Examples
{
    class MyMainClass
    {
        public static void
 Main()
        {

            // Create a new instance of the RC2CryptoServiceProvider
 class
            // and automatically generate a Key and IV.
            RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider();

            Console.WriteLine("Effective key size is {0} bits.", rc2CSP.EffectiveKeySize);

            // Get the key and IV.
            byte[] key = rc2CSP.Key;
            byte[] IV = rc2CSP.IV;

            // Get an encryptor.
            ICryptoTransform encryptor = rc2CSP.CreateEncryptor(key, IV);

            // Encrypt the data as an array of encrypted bytes in memory.
            MemoryStream msEncrypt = new MemoryStream();
            CryptoStream csEncrypt = new CryptoStream(msEncrypt,
 encryptor, CryptoStreamMode.Write);

            // Convert the data to a byte array.
            string original = "Here is some data to encrypt.";
            byte[] toEncrypt = Encoding.ASCII.GetBytes(original);

            // Write all data to the crypto stream and flush it.
            csEncrypt.Write(toEncrypt, 0, toEncrypt.Length);
            csEncrypt.FlushFinalBlock();

            // Get the encrypted array of bytes.
            byte[] encrypted = msEncrypt.ToArray();

            ///////////////////////////////////////////////////////
            // This is where the data could be transmitted or saved.
          
            ///////////////////////////////////////////////////////

            //Get a decryptor that uses the same key and IV as the encryptor.
            ICryptoTransform decryptor = rc2CSP.CreateDecryptor(key, IV);

            // Now decrypt the previously encrypted message using the
 decryptor
            // obtained in the above step.
            MemoryStream msDecrypt = new MemoryStream(encrypted);
            CryptoStream csDecrypt = new CryptoStream(msDecrypt,
 decryptor, CryptoStreamMode.Read);

            byte[] fromEncrypt = new byte[toEncrypt.Length];

            // Read the data out of the crypto stream.
            csDecrypt.Read(fromEncrypt, 0, toEncrypt.Length);

            // Convert the byte array back into a string.
            String roundtrip = Encoding.ASCII.GetString(fromEncrypt);

            // Display the original data and the decrypted data.
            Console.WriteLine("Original:   {0}", original);
            Console.WriteLine("Round Trip: {0}", roundtrip);

            Console.ReadLine();
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RC2CryptoServiceProvider クラス
RC2CryptoServiceProvider メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス



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

辞書ショートカット

すべての辞書の索引

「RC2CryptoServiceProvider コンストラクタ」の関連用語

RC2CryptoServiceProvider コンストラクタのお隣キーワード
検索ランキング

   

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



RC2CryptoServiceProvider コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS