SymmetricAlgorithm 클래스

정의

모든 대칭 알고리즘의 구현에서 상속해야 하는 추상 기본 클래스를 나타냅니다.

public ref class SymmetricAlgorithm abstract : IDisposable
public abstract class SymmetricAlgorithm : IDisposable
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class SymmetricAlgorithm : IDisposable
type SymmetricAlgorithm = class
    interface IDisposable
[<System.Runtime.InteropServices.ComVisible(true)>]
type SymmetricAlgorithm = class
    interface IDisposable
Public MustInherit Class SymmetricAlgorithm
Implements IDisposable
상속
SymmetricAlgorithm
파생
특성
구현

예제

다음 코드 예제에서는 지정된 Key 속성 및 초기화 벡터(IV)가 있는 클래스를 사용하여 Aes 지정된 inName파일을 암호화하고 암호화된 결과를 지정된 outName파일에 출력합니다. 메서드의 매개 변수 및 desIV 매개 변수는 desKey 8 바이트 배열입니다. 이 예제를 실행하려면 높은 암호화 팩이 설치되어 있어야 합니다.

void EncryptData( String^ inName, String^ outName, array<Byte>^aesKey, array<Byte>^aesIV )
{
   
   //Create the file streams to handle the input and output files.
   FileStream^ fin = gcnew FileStream( inName,FileMode::Open,FileAccess::Read );
   FileStream^ fout = gcnew FileStream( outName,FileMode::OpenOrCreate,FileAccess::Write );
   fout->SetLength( 0 );
   
   //Create variables to help with read and write.
   array<Byte>^bin = gcnew array<Byte>(100);
   long rdlen = 0; //This is the total number of bytes written.

   long totlen = (long)fin->Length; //This is the total length of the input file.

   int len; //This is the number of bytes to be written at a time.

   Aes^ aes = Aes::Create();

   CryptoStream^ encStream = gcnew CryptoStream( fout,aes->CreateEncryptor( aesKey, aesIV ),CryptoStreamMode::Write );
   Console::WriteLine( "Encrypting..." );
   
   //Read from the input file, then encrypt and write to the output file.
   while ( rdlen < totlen )
   {
      len = fin->Read( bin, 0, 100 );
      encStream->Write( bin, 0, len );
      rdlen = rdlen + len;
      Console::WriteLine( "{0} bytes processed", rdlen );
   }

   encStream->Close();
   fout->Close();
   fin->Close();
}
private static void EncryptData(string inName, string outName, byte[] aesKey, byte[] aesIV)
 {
     //Create the file streams to handle the input and output files.
     FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
     FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
     fout.SetLength(0);

     //Create variables to help with read and write.
     byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
     long rdlen = 0;              //This is the total number of bytes written.
     long totlen = fin.Length;    //This is the total length of the input file.
     int len;                     //This is the number of bytes to be written at a time.

     Aes aes = Aes.Create();
     CryptoStream encStream = new CryptoStream(fout, aes.CreateEncryptor(aesKey, aesIV), CryptoStreamMode.Write);

     Console.WriteLine("Encrypting...");

     //Read from the input file, then encrypt and write to the output file.
     while(rdlen < totlen)
     {
         len = fin.Read(bin, 0, 100);
         encStream.Write(bin, 0, len);
         rdlen = rdlen + len;
         Console.WriteLine("{0} bytes processed", rdlen);
     }

     encStream.Close();
     fout.Close();
     fin.Close();
 }
Private Shared Sub EncryptData(inName As String, outName As String, _
rijnKey() As Byte, rijnIV() As Byte)

    'Create the file streams to handle the input and output files.
    Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read)
    Dim fout As New FileStream(outName, FileMode.OpenOrCreate, _
       FileAccess.Write)
    fout.SetLength(0)
    
    'Create variables to help with read and write.
    Dim bin(100) As Byte 'This is intermediate storage for the encryption.
    Dim rdlen As Long = 0 'This is the total number of bytes written.
    Dim totlen As Long = fin.Length 'Total length of the input file.
    Dim len As Integer 'This is the number of bytes to be written at a time.
    'Creates the default implementation, which is RijndaelManaged.
    Dim rijn As SymmetricAlgorithm = SymmetricAlgorithm.Create()
    Dim encStream As New CryptoStream(fout, _
       rijn.CreateEncryptor(rijnKey, rijnIV), CryptoStreamMode.Write)
    
    Console.WriteLine("Encrypting...")
    
    'Read from the input file, then encrypt and write to the output file.
    While rdlen < totlen
        len = fin.Read(bin, 0, 100)
        encStream.Write(bin, 0, len)
        rdlen = Convert.ToInt32(rdlen + len)
        Console.WriteLine("{0} bytes processed", rdlen)
    End While
    
    encStream.Close()
fout.Close()
fin.Close()
End Sub

설명

클래스에서 SymmetricAlgorithm 파생되는 클래스는 데이터에 대한 암호화 변환을 수행하기 위해 키() 및 초기화 벡터(Key)가 필요한 CBC(IV암호 블록 체인)라는 체인 모드를 사용합니다. 클래스 중 SymmetricAlgorithm 하나를 사용하여 암호화된 데이터의 암호를 해독하려면 속성과 IV 속성을 암호화에 사용된 것과 동일한 값으로 설정 Key 해야 합니다. 대칭 알고리즘이 유용하려면 비밀 키를 보낸 사람 및 수신자에게만 알려야 합니다.

Aes, DESRC2TripleDES 대칭 알고리즘의 구현입니다.

파생 클래스를 사용하는 경우 보안 관점에서 개체 사용을 완료한 후에 가비지 수집을 강제로 적용하는 것만으로는 충분하지 않습니다. 개체가 해제되기 전에 개체 내의 Clear 중요한 데이터를 0으로 0으로 하려면 개체의 메서드를 명시적으로 호출해야 합니다. 가비지 수집은 수집된 개체의 콘텐츠를 0으로 표시하지 않고 단순히 메모리를 다시 할당에 사용할 수 있는 것으로 표시합니다. 따라서 가비지 수집된 개체 내에 포함된 데이터는 할당되지 않은 메모리의 메모리 힙에 여전히 있을 수 있습니다. 암호화 개체의 경우 이 데이터에는 키 데이터 또는 일반 텍스트 블록과 같은 중요한 정보가 포함될 수 있습니다.

중요한 데이터를 포함하는 .NET Framework 모든 암호화 클래스는 메서드를 Clear 구현합니다. 호출될 때 메서드는 Clear 개체 내의 모든 중요한 데이터를 0으로 덮어쓰고 안전하게 가비지 수집할 수 있도록 개체를 해제합니다. 개체가 0으로 설정되고 해제된 경우 매개 변수가 설정된 메서드 disposing 를 호출 Dispose 하여 True 개체와 연결된 모든 관리 및 관리되지 않는 리소스를 삭제해야 합니다.

구현자 참고

상속 하는 경우는 SymmetricAlgorithm 클래스 멤버를 재정의 해야 합니다: CreateDecryptor(Byte[], Byte[])CreateEncryptor(Byte[], Byte[])GenerateIV(), 및 GenerateKey()합니다.

생성자

SymmetricAlgorithm()

SymmetricAlgorithm 클래스의 새 인스턴스를 초기화합니다.

필드

BlockSizeValue

암호화 작업의 블록 크기(비트)를 나타냅니다.

FeedbackSizeValue

암호화 작업의 피드백 크기(비트 단위)를 나타냅니다.

IVValue

대칭 알고리즘에 대한 초기화 벡터(IV)를 나타냅니다.

KeySizeValue

대칭 알고리즘에서 사용하는 비밀 키의 크기(비트 단위)를 나타냅니다.

KeyValue

대칭 알고리즘에 대한 비밀 키를 나타냅니다.

LegalBlockSizesValue

대칭 알고리즘에서 지원하는 블록 크기(비트 단위)를 지정합니다.

LegalKeySizesValue

대칭 알고리즘에서 지원하는 키 크기(비트 단위)를 지정합니다.

ModeValue

대칭 알고리즘에 사용된 암호화 모드를 나타냅니다.

PaddingValue

대칭 알고리즘에 사용된 패딩 모드를 나타냅니다.

속성

BlockSize

암호화 작업의 블록 크기(비트 단위)를 가져오거나 설정합니다.

FeedbackSize

CFB(Cipher Feedback) 및 OFB(Output Feedback) 암호화 모드에 대한 암호화 작업의 피드백 크기(비트 단위)를 가져오거나 설정합니다.

IV

대칭 알고리즘에 대한 초기화 벡터(IV)를 가져오거나 설정합니다.

Key

대칭 알고리즘에 대한 비밀 키를 가져오거나 설정합니다.

KeySize

대칭 알고리즘에서 사용하는 비밀 키의 크기(비트 단위)를 가져오거나 설정합니다.

LegalBlockSizes

대칭 알고리즘에서 지원하는 블록 크기(비트 단위)를 가져옵니다.

LegalKeySizes

대칭 알고리즘에서 지원하는 키 크기(비트 단위)를 가져옵니다.

Mode

대칭 알고리즘의 작업 모드를 가져오거나 설정합니다.

Padding

대칭 알고리즘에 사용된 패딩 모드를 가져오거나 설정합니다.

메서드

Clear()

SymmetricAlgorithm 클래스에서 사용하는 모든 리소스를 해제합니다.

Create()
사용되지 않습니다.
사용되지 않습니다.

대칭 알고리즘을 수행하는 데 사용되는 기본 암호화 개체를 만듭니다.

Create(String)

대칭 알고리즘을 수행하는 데 사용되는 지정된 암호화 개체를 만듭니다.

CreateDecryptor()

현재 Key 속성 및 초기화 벡터(IV)를 사용하여 대칭 decryptor 개체를 만듭니다.

CreateDecryptor(Byte[], Byte[])

파생 클래스에서 재정의된 경우 지정된 Key 속성 및 초기화 벡터(IV)를 사용하여 대칭 decryptor 개체를 만듭니다.

CreateEncryptor()

현재 Key 속성 및 초기화 벡터(IV)를 사용하여 대칭 encryptor 개체를 만듭니다.

CreateEncryptor(Byte[], Byte[])

파생 클래스에서 재정의된 경우 지정된 Key 속성 및 초기화 벡터(IV)를 사용하여 대칭 encryptor 개체를 만듭니다.

DecryptCbc(Byte[], Byte[], PaddingMode)

지정된 패딩 모드에서 CBC 모드를 사용하여 데이터를 해독합니다.

DecryptCbc(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, PaddingMode)

지정된 패딩 모드에서 CBC 모드를 사용하여 데이터를 해독합니다.

DecryptCbc(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode)

지정된 패딩 모드에서 CBC 모드를 사용하여 데이터를 지정된 버퍼로 해독합니다.

DecryptCfb(Byte[], Byte[], PaddingMode, Int32)

지정된 안쪽 여백 모드 및 피드백 크기로 CFB 모드를 사용하여 데이터를 해독합니다.

DecryptCfb(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, PaddingMode, Int32)

지정된 안쪽 여백 모드 및 피드백 크기로 CFB 모드를 사용하여 데이터를 해독합니다.

DecryptCfb(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32)

지정된 패딩 모드 및 피드백 크기가 있는 CFB 모드를 사용하여 데이터를 지정된 버퍼로 해독합니다.

DecryptEcb(Byte[], PaddingMode)

지정된 패딩 모드를 사용하여 ECB 모드를 사용하여 데이터를 해독합니다.

DecryptEcb(ReadOnlySpan<Byte>, PaddingMode)

지정된 패딩 모드를 사용하여 ECB 모드를 사용하여 데이터를 해독합니다.

DecryptEcb(ReadOnlySpan<Byte>, Span<Byte>, PaddingMode)

지정된 패딩 모드에서 ECB 모드를 사용하여 데이터를 지정된 버퍼로 해독합니다.

Dispose()

SymmetricAlgorithm 클래스의 현재 인스턴스에서 사용하는 모든 리소스를 해제합니다.

Dispose(Boolean)

SymmetricAlgorithm에서 사용하는 관리되지 않는 리소스를 해제하고, 관리되는 리소스를 선택적으로 해제할 수 있습니다.

EncryptCbc(Byte[], Byte[], PaddingMode)

지정된 패딩 모드로 CBC 모드를 사용하여 데이터를 암호화합니다.

EncryptCbc(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, PaddingMode)

지정된 패딩 모드로 CBC 모드를 사용하여 데이터를 암호화합니다.

EncryptCbc(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode)

지정된 패딩 모드가 있는 CBC 모드를 사용하여 데이터를 지정된 버퍼로 암호화합니다.

EncryptCfb(Byte[], Byte[], PaddingMode, Int32)

지정된 패딩 모드 및 피드백 크기로 CFB 모드를 사용하여 데이터를 암호화합니다.

EncryptCfb(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, PaddingMode, Int32)

지정된 패딩 모드 및 피드백 크기로 CFB 모드를 사용하여 데이터를 암호화합니다.

EncryptCfb(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32)

지정된 패딩 모드 및 피드백 크기가 있는 CFB 모드를 사용하여 데이터를 지정된 버퍼로 암호화합니다.

EncryptEcb(Byte[], PaddingMode)

지정된 패딩 모드로 ECB 모드를 사용하여 데이터를 암호화합니다.

EncryptEcb(ReadOnlySpan<Byte>, PaddingMode)

지정된 패딩 모드로 ECB 모드를 사용하여 데이터를 암호화합니다.

EncryptEcb(ReadOnlySpan<Byte>, Span<Byte>, PaddingMode)

지정된 패딩 모드에서 ECB 모드를 사용하여 데이터를 지정된 버퍼로 암호화합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
Finalize()

이 멤버는 Finalize()를 재정의합니다. 자세한 내용은 해당 항목을 참조하세요.

가비지 수집기에서 Object를 회수하기 전에 Object가 리소스를 해제하고 다른 정리 작업을 수행할 수 있게 합니다.

GenerateIV()

파생 클래스에서 재정의된 경우 알고리즘에 사용할 임의의 초기화 벡터(IV)를 생성합니다.

GenerateKey()

파생 클래스에서 재정의된 경우 알고리즘에 사용할 난수 키(Key)를 생성합니다.

GetCiphertextLengthCbc(Int32, PaddingMode)

CBC 모드에서 지정된 패딩 모드 및 일반 텍스트 길이가 있는 암호 텍스트의 길이를 가져옵니다.

GetCiphertextLengthCfb(Int32, PaddingMode, Int32)

CFB 모드에서 지정된 패딩 모드 및 일반 텍스트 길이가 있는 암호 텍스트의 길이를 가져옵니다.

GetCiphertextLengthEcb(Int32, PaddingMode)

ECB 모드에서 지정된 패딩 모드 및 일반 텍스트 길이가 있는 암호 텍스트의 길이를 가져옵니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
TryDecryptCbc(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, Int32, PaddingMode)

지정된 패딩 모드에서 CBC 모드를 사용하여 데이터를 지정된 버퍼로 암호 해독하려고 시도합니다.

TryDecryptCbcCore(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32)

파생 클래스에서 재정의된 경우 지정된 패딩 모드에서 CBC 모드를 사용하여 데이터를 지정된 버퍼로 암호 해독하려고 시도합니다.

TryDecryptCfb(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, Int32, PaddingMode, Int32)

지정된 패딩 모드 및 피드백 크기가 있는 CFB 모드를 사용하여 데이터를 지정된 버퍼로 암호 해독하려고 시도합니다.

TryDecryptCfbCore(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32, Int32)

파생 클래스에서 재정의된 경우 지정된 패딩 모드 및 피드백 크기가 있는 CFB 모드를 사용하여 지정된 버퍼로 데이터를 해독하려고 시도합니다.

TryDecryptEcb(ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32)

지정된 패딩 모드가 있는 ECB 모드를 사용하여 데이터를 지정된 버퍼로 암호 해독하려고 시도합니다.

TryDecryptEcbCore(ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32)

파생 클래스에서 재정의된 경우 지정된 패딩 모드가 있는 ECB 모드를 사용하여 데이터를 지정된 버퍼로 해독하려고 시도합니다.

TryEncryptCbc(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, Int32, PaddingMode)

지정된 패딩 모드에서 CBC 모드를 사용하여 지정된 버퍼로 데이터를 암호화하려고 시도합니다.

TryEncryptCbcCore(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32)

파생 클래스에서 재정의된 경우 지정된 패딩 모드가 있는 CBC 모드를 사용하여 지정된 버퍼로 데이터를 암호화하려고 시도합니다.

TryEncryptCfb(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, Int32, PaddingMode, Int32)

지정된 패딩 모드 및 피드백 크기가 있는 CFB 모드를 사용하여 지정된 버퍼로 데이터를 암호화하려고 시도합니다.

TryEncryptCfbCore(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32, Int32)

파생 클래스에서 재정의된 경우 지정된 패딩 모드 및 피드백 크기가 있는 CFB 모드를 사용하여 데이터를 지정된 버퍼로 암호화하려고 시도합니다.

TryEncryptEcb(ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32)

지정된 패딩 모드에서 ECB 모드를 사용하여 지정된 버퍼로 데이터를 암호화하려고 시도합니다.

TryEncryptEcbCore(ReadOnlySpan<Byte>, Span<Byte>, PaddingMode, Int32)

파생 클래스에서 재정의된 경우 지정된 패딩 모드가 있는 ECB 모드를 사용하여 데이터를 지정된 버퍼로 암호화하려고 시도합니다.

ValidKeySize(Int32)

지정된 키 크기를 현재 알고리즘에 사용할 수 있는지 여부를 결정합니다.

명시적 인터페이스 구현

IDisposable.Dispose()

이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다.

SymmetricAlgorithm에서 사용하는 관리되지 않는 리소스를 해제하고, 관리되는 리소스를 선택적으로 해제할 수 있습니다.

적용 대상

추가 정보