RC2CryptoServiceProvider クラスとは? わかりやすく解説

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

RC2CryptoServiceProvider クラス

RC2 アルゴリズム暗号サービス プロバイダ (CSP : Cryptographic Service Provider) 実装アクセスするためのラッパー オブジェクト定義します。このクラス継承できません。

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

<ComVisibleAttribute(True)> _
Public NotInheritable Class
 RC2CryptoServiceProvider
    Inherits RC2
Dim instance As RC2CryptoServiceProvider
[ComVisibleAttribute(true)] 
public sealed class RC2CryptoServiceProvider
 : RC2
[ComVisibleAttribute(true)] 
public ref class RC2CryptoServiceProvider sealed
 : public RC2
/** @attribute ComVisibleAttribute(true) */ 
public final class RC2CryptoServiceProvider
 extends RC2
ComVisibleAttribute(true) 
public final class RC2CryptoServiceProvider
 extends RC2
解説解説

RC2CryptoServiceProvider実装では、40 ビットから 128 ビットキー長を 8 ビット単位サポートします

RC2CryptoServiceProvider オブジェクトは、データ暗号化と復号化を 8 バイトブロック単位で行うブロック暗号です。最終ブロックデータが 8 バイト未満場合、このクラス不足分データ埋め込みます。データ埋め込まれることにより、暗号化されたデータ長さが、元の平文長さ超える場合あります

RC2CryptoServiceProvider オブジェクトsalt使用しません。

使用例使用例

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

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();
        }
    }
}
継承階層継承階層
System.Object
   System.Security.Cryptography.SymmetricAlgorithm
     System.Security.Cryptography.RC2
      System.Security.Cryptography.RC2CryptoServiceProvider
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RC2CryptoServiceProvider メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス


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

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

辞書ショートカット

すべての辞書の索引

「RC2CryptoServiceProvider クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS