RC2CryptoServiceProvider 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
주의
Derived cryptographic types are obsolete. Use the Create method on the base type instead.
래퍼 개체를 정의하여 RC2 알고리즘의 CSP(암호화 서비스 공급자) 구현에 액세스합니다. 이 클래스는 상속될 수 없습니다.
public ref class RC2CryptoServiceProvider sealed : System::Security::Cryptography::RC2
public sealed class RC2CryptoServiceProvider : System.Security.Cryptography.RC2
[System.Obsolete("Derived cryptographic types are obsolete. Use the Create method on the base type instead.", DiagnosticId="SYSLIB0021", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public sealed class RC2CryptoServiceProvider : System.Security.Cryptography.RC2
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class RC2CryptoServiceProvider : System.Security.Cryptography.RC2
type RC2CryptoServiceProvider = class
inherit RC2
[<System.Obsolete("Derived cryptographic types are obsolete. Use the Create method on the base type instead.", DiagnosticId="SYSLIB0021", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type RC2CryptoServiceProvider = class
inherit RC2
[<System.Runtime.InteropServices.ComVisible(true)>]
type RC2CryptoServiceProvider = class
inherit RC2
Public NotInheritable Class RC2CryptoServiceProvider
Inherits RC2
- 상속
- 특성
예제
다음 코드 예제에서는 문자열을 암호화한 다음 암호를 해독합니다.
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);
// Read the decrypted bytes from the decrypting stream
// and place them in a StringBuilder class.
StringBuilder roundtrip = new StringBuilder();
int b = 0;
do
{
b = csDecrypt.ReadByte();
if (b != -1)
{
roundtrip.Append((char)b);
}
} while (b != -1);
// Display the original data and the decrypted data.
Console.WriteLine("Original: {0}", original);
Console.WriteLine("Round Trip: {0}", roundtrip);
}
}
}
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Module Crypto
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)
' Read the decrypted bytes from the decrypting stream
' and place them in a StringBuilder class.
Dim roundtrip As New StringBuilder()
Dim b As Integer = 0
Do
b = csDecrypt.ReadByte()
If b <> -1 Then
roundtrip.Append(ChrW(b))
End If
Loop While b <> -1
' Display the original data and the decrypted data.
Console.WriteLine("Original: {0}", original)
Console.WriteLine("Round Trip: {0}", roundtrip)
End Sub
End Module
설명
구현은 RC2CryptoServiceProvider 8비트 단위로 40비트에서 128비트까지의 키 길이를 지원합니다.
개체는 RC2CryptoServiceProvider 8바이트 블록으로 데이터를 암호화하고 암호를 해독하는 블록 암호입니다. 이 클래스는 8바이트 미만인 경우 데이터의 마지막 블록을 채 니다. 이 패딩의 결과로 암호화된 데이터의 길이가 원래 일반 텍스트보다 클 수 있습니다.
개체는 솔트 RC2CryptoServiceProvider (salt)를 사용하지 않습니다.
참고
최신 대칭 암호화 알고리즘인 AES(Advanced Encryption Standard)를 사용할 수 있습니다. 클래스 대신 RC2CryptoServiceProvider 알고리즘 및 파생 클래스를 사용하는 Aes 것이 좋습니다. 사용 하 여 RC2CryptoServiceProvider 레거시 애플리케이션 및 데이터를 사용 하 여 호환성을 위해서만 합니다.
생성자
RC2CryptoServiceProvider() |
사용되지 않음.
RC2CryptoServiceProvider 클래스의 새 인스턴스를 초기화합니다. |
필드
BlockSizeValue |
사용되지 않음.
암호화 작업의 블록 크기(비트)를 나타냅니다. (다음에서 상속됨 SymmetricAlgorithm) |
EffectiveKeySizeValue |
사용되지 않음.
RC2 알고리즘이 bps 단위로 사용한 비밀 키의 효과적인 크기를 나타냅니다. (다음에서 상속됨 RC2) |
FeedbackSizeValue |
사용되지 않음.
암호화 작업의 피드백 크기(비트 단위)를 나타냅니다. (다음에서 상속됨 SymmetricAlgorithm) |
IVValue |
사용되지 않음.
대칭 알고리즘에 대한 초기화 벡터(IV)를 나타냅니다. (다음에서 상속됨 SymmetricAlgorithm) |
KeySizeValue |
사용되지 않음.
대칭 알고리즘에서 사용하는 비밀 키의 크기(비트 단위)를 나타냅니다. (다음에서 상속됨 SymmetricAlgorithm) |
KeyValue |
사용되지 않음.
대칭 알고리즘에 대한 비밀 키를 나타냅니다. (다음에서 상속됨 SymmetricAlgorithm) |
LegalBlockSizesValue |
사용되지 않음.
대칭 알고리즘에서 지원하는 블록 크기(비트 단위)를 지정합니다. (다음에서 상속됨 SymmetricAlgorithm) |
LegalKeySizesValue |
사용되지 않음.
대칭 알고리즘에서 지원하는 키 크기(비트 단위)를 지정합니다. (다음에서 상속됨 SymmetricAlgorithm) |
ModeValue |
사용되지 않음.
대칭 알고리즘에 사용된 암호화 모드를 나타냅니다. (다음에서 상속됨 SymmetricAlgorithm) |
PaddingValue |
사용되지 않음.
대칭 알고리즘에 사용된 패딩 모드를 나타냅니다. (다음에서 상속됨 SymmetricAlgorithm) |
속성
BlockSize |
사용되지 않음.
암호화 작업의 블록 크기(비트 단위)를 가져오거나 설정합니다. (다음에서 상속됨 SymmetricAlgorithm) |
EffectiveKeySize |
사용되지 않음.
RC2 알고리즘에서 사용하는 비밀 키의 효과적인 크기(비트 단위)를 가져오거나 설정합니다. |
FeedbackSize |
사용되지 않음.
CFB(Cipher Feedback) 및 OFB(Output Feedback) 암호화 모드에 대한 암호화 작업의 피드백 크기(비트 단위)를 가져오거나 설정합니다. (다음에서 상속됨 SymmetricAlgorithm) |
IV |
사용되지 않음.
대칭 알고리즘에 대한 초기화 벡터(IV)를 가져오거나 설정합니다. (다음에서 상속됨 SymmetricAlgorithm) |
Key |
사용되지 않음.
대칭 알고리즘에 대한 비밀 키를 가져오거나 설정합니다. (다음에서 상속됨 SymmetricAlgorithm) |
KeySize |
사용되지 않음.
RC2 알고리즘에서 사용하는 비밀 키의 크기(비트)를 가져오거나 설정합니다. (다음에서 상속됨 RC2) |
LegalBlockSizes |
사용되지 않음.
대칭 알고리즘에서 지원하는 블록 크기(비트 단위)를 가져옵니다. (다음에서 상속됨 SymmetricAlgorithm) |
LegalKeySizes |
사용되지 않음.
대칭 알고리즘에서 지원하는 키 크기(비트 단위)를 가져옵니다. (다음에서 상속됨 SymmetricAlgorithm) |
Mode |
사용되지 않음.
대칭 알고리즘의 작업 모드를 가져오거나 설정합니다. (다음에서 상속됨 SymmetricAlgorithm) |
Padding |
사용되지 않음.
대칭 알고리즘에 사용된 패딩 모드를 가져오거나 설정합니다. (다음에서 상속됨 SymmetricAlgorithm) |
UseSalt |
사용되지 않음.
11바이트 길이의 0값 솔트를 사용하여 키를 만들 것인지 여부를 결정하는 값을 가져오거나 설정합니다. |
메서드
명시적 인터페이스 구현
IDisposable.Dispose() |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다.
사용되지 않음.
SymmetricAlgorithm에서 사용하는 관리되지 않는 리소스를 해제하고, 관리되는 리소스를 선택적으로 해제할 수 있습니다. (다음에서 상속됨 SymmetricAlgorithm) |
적용 대상
추가 정보
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기