.NET 도움말 C# AES Encryption (How It Works For Developers) 커티스 차우 업데이트됨:7월 28, 2025 다운로드 IronPDF NuGet 다운로드 DLL 다운로드 윈도우 설치 프로그램 무료 체험 시작하기 LLM용 사본 LLM용 사본 LLM용 마크다운 형식으로 페이지를 복사하세요 ChatGPT에서 열기 ChatGPT에 이 페이지에 대해 문의하세요 제미니에서 열기 제미니에게 이 페이지에 대해 문의하세요 Grok에서 열기 Grok에게 이 페이지에 대해 문의하세요 혼란 속에서 열기 Perplexity에게 이 페이지에 대해 문의하세요 공유하다 페이스북에 공유하기 트위터에 공유하기 LinkedIn에 공유하기 URL 복사 이메일로 기사 보내기 AES (Advanced Encryption Standard) is one of the most commonly used symmetric encryption algorithms. It uses the same key to encrypt and decrypt data, making AES encryption efficient and fast for securing sensitive data in many applications. This tutorial will focus on AES encryption in C#, using the AES class to encrypt and decrypt data and IronPDF Library. We’ll cover practical examples, walk through the encryption process, and see how to use Cipher Block Chaining (CBC) mode to increase security. We’ll also discuss encryption key management and the role of the initialization vector (IV). Introduction of AES Encryption in C# Advanced Encryption Standard (AES) is a symmetric encryption algorithm standardized by the National Institute of Standards and Technology (NIST). The algorithm can have key sizes of 128, 192, or 256 bits and is highly secure for encrypting confidential data. It uses the same encryption key to encrypt and decrypt data. AES works by splitting the original data into blocks and applying transformations on those blocks. It operates in different cipher modes, such as CBC (Cipher Block Chaining) and Electronic CodeBook (ECB), each providing different security features. How AES Works in C# The AES encryption algorithm in C# is part of the System.Security.Cryptography namespace. This namespace includes the AES class, which allows us to create an instance of AES, specify the key size, cipher mode, and padding mode, and then encrypt and decrypt data using a secret key. To use AES in C#, follow these basic steps: Create an instance of the AES class using Aes.Create(). Set the key, IV, and other relevant parameters like cipher mode. Encrypt the data using the ICryptoTransform interface and write it to a MemoryStream. Decrypt the data using the same key and IV. Let’s create a basic encryption process and decryption program in C#. using System; using System.IO; using System.Security.Cryptography; using System.Text; class Program { // Declare a static byte array for encrypted data public static byte[] encryptedData; // Main method to demonstrate encryption and decryption public static void Main(string[] args) { // String plaintext to be encrypted string plaintext = "This is some sensitive data!"; string key = "abcdefghijklmnop"; // 128-bit key (16 characters) // Encrypt the plaintext string ciphertext = Encrypt(plaintext, key); Console.WriteLine("Encrypted Data: " + ciphertext); // Decrypt the ciphertext string decryptedData = Decrypt(ciphertext, key); Console.WriteLine("Decrypted Data: " + decryptedData); } // Method to encrypt data public static string Encrypt(string plaintext, string key) { // Create a new instance of the AES encryption algorithm using (Aes aes = Aes.Create()) { aes.Key = Encoding.UTF8.GetBytes(key); aes.IV = new byte[16]; // Initialization vector (IV) // Create an encryptor to perform the stream transform ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); // Create the streams used for encryption using (MemoryStream ms = new MemoryStream()) { // Create a CryptoStream using the encryptor using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write)) { using (StreamWriter sw = new StreamWriter(cs)) { sw.Write(plaintext); } } // Store the encrypted data in the public static byte array encryptedData = ms.ToArray(); return Convert.ToBase64String(encryptedData); } } } // Method to decrypt data public static string Decrypt(string ciphertext, string key) { using (Aes aes = Aes.Create()) { aes.Key = Encoding.UTF8.GetBytes(key); aes.IV = new byte[16]; // Initialization vector (IV) // Create a decryptor to perform the stream transform ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); // Create the streams used for decryption using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(ciphertext))) { using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read)) { using (StreamReader sr = new StreamReader(cs)) { return sr.ReadToEnd(); } } } } } } using System; using System.IO; using System.Security.Cryptography; using System.Text; class Program { // Declare a static byte array for encrypted data public static byte[] encryptedData; // Main method to demonstrate encryption and decryption public static void Main(string[] args) { // String plaintext to be encrypted string plaintext = "This is some sensitive data!"; string key = "abcdefghijklmnop"; // 128-bit key (16 characters) // Encrypt the plaintext string ciphertext = Encrypt(plaintext, key); Console.WriteLine("Encrypted Data: " + ciphertext); // Decrypt the ciphertext string decryptedData = Decrypt(ciphertext, key); Console.WriteLine("Decrypted Data: " + decryptedData); } // Method to encrypt data public static string Encrypt(string plaintext, string key) { // Create a new instance of the AES encryption algorithm using (Aes aes = Aes.Create()) { aes.Key = Encoding.UTF8.GetBytes(key); aes.IV = new byte[16]; // Initialization vector (IV) // Create an encryptor to perform the stream transform ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); // Create the streams used for encryption using (MemoryStream ms = new MemoryStream()) { // Create a CryptoStream using the encryptor using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write)) { using (StreamWriter sw = new StreamWriter(cs)) { sw.Write(plaintext); } } // Store the encrypted data in the public static byte array encryptedData = ms.ToArray(); return Convert.ToBase64String(encryptedData); } } } // Method to decrypt data public static string Decrypt(string ciphertext, string key) { using (Aes aes = Aes.Create()) { aes.Key = Encoding.UTF8.GetBytes(key); aes.IV = new byte[16]; // Initialization vector (IV) // Create a decryptor to perform the stream transform ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); // Create the streams used for decryption using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(ciphertext))) { using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read)) { using (StreamReader sr = new StreamReader(cs)) { return sr.ReadToEnd(); } } } } } } $vbLabelText $csharpLabel Explanation of Code Aes.Create(): This creates a new instance of the AES encryption algorithm. aes.Key: The key used for both encryption and decryption. It must be of a valid size, such as 128 bits (16 bytes), 192 bits, or 256 bits. aes.IV: The initialization vector (IV), is used to randomize the encryption process. In this example, we use an IV of zeros for simplicity. MemoryStream: This allows us to work with the encrypted data as a stream of bytes. CryptoStream: It transforms the data stream (encryption or decryption). Advanced Example: AES Encryption with Custom Key and IV Let’s build upon the previous example by generating a random key and IV, ensuring the encryption is more secure. public static string EncryptData(string plaintext) { using (Aes aes = Aes.Create()) { aes.Key = new byte[32]; // AES-256 requires a 256-bit key (32 bytes) aes.IV = new byte[16]; // 128-bit block size // Randomly generate key and IV using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { rng.GetBytes(aes.Key); // Generate a random key rng.GetBytes(aes.IV); // Generate a random IV } // Create an encryptor to perform the stream transform ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); // Create the streams used for encryption using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write)) { using (StreamWriter sw = new StreamWriter(cs)) { sw.Write(plaintext); } } return Convert.ToBase64String(ms.ToArray()); } } } public static string EncryptData(string plaintext) { using (Aes aes = Aes.Create()) { aes.Key = new byte[32]; // AES-256 requires a 256-bit key (32 bytes) aes.IV = new byte[16]; // 128-bit block size // Randomly generate key and IV using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { rng.GetBytes(aes.Key); // Generate a random key rng.GetBytes(aes.IV); // Generate a random IV } // Create an encryptor to perform the stream transform ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); // Create the streams used for encryption using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write)) { using (StreamWriter sw = new StreamWriter(cs)) { sw.Write(plaintext); } } return Convert.ToBase64String(ms.ToArray()); } } } $vbLabelText $csharpLabel In this case, we generate a new key and IV each time the function is called. This provides more robust encryption as the same key is unused for every operation. AES supports key sizes such as 128, 192, and 256 bits. Decrypting Data with AES Decryption is the reverse process to encrypt data. In our examples, the same key and IV used for encryption must be provided to decrypt the data. The decryption process involves converting the encrypted data back into its original form. Here’s an example that uses the previously encrypted data: public static string DecryptData(string ciphertext, byte[] key, byte[] iv) { using (Aes aes = Aes.Create()) { aes.Key = key; aes.IV = iv; // Create a decryptor to perform the stream transform ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); // Create the streams used for decryption using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(ciphertext))) { using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read)) { using (StreamReader sr = new StreamReader(cs)) { return sr.ReadToEnd(); } } } } } public static string DecryptData(string ciphertext, byte[] key, byte[] iv) { using (Aes aes = Aes.Create()) { aes.Key = key; aes.IV = iv; // Create a decryptor to perform the stream transform ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); // Create the streams used for decryption using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(ciphertext))) { using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read)) { using (StreamReader sr = new StreamReader(cs)) { return sr.ReadToEnd(); } } } } } $vbLabelText $csharpLabel This code decrypts the encrypted data back into the original data. IronPDF with AES Encryption IronPDF is a simple and developer-friendly .NET library designed to generate, edit, and manipulate PDFs using simple C# code. It allows developers to create PDF documents directly from HTML, CSS, and JavaScript, which can be incredibly useful for dynamically generating reports, invoices, or other documents. With support for merging, splitting, and even adding security features like passwords or digital signatures, IronPDF is a comprehensive solution for PDF generation in .NET applications. Integrating IronPDF with AES Encryption When you generate sensitive reports or documents, you may need to ensure the data within those PDFs is encrypted before sharing. AES (Advanced Encryption Standard) encryption is a perfect solution for securely encrypting the contents of PDF files. By combining IronPDF and AES encryption, you can protect the data within your PDFs while maintaining the ability to work with the document itself. Step 1: Create a PDF Using IronPDF Use the ChromePdfRenderer class to generate a PDF from HTML content and save it to a file: var htmlContent = "<h1>Confidential</h1><p>This is sensitive data.</p>"; var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf(htmlContent); pdf.SaveAs(@"C:\Reports\ConfidentialReport.pdf"); var htmlContent = "<h1>Confidential</h1><p>This is sensitive data.</p>"; var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf(htmlContent); pdf.SaveAs(@"C:\Reports\ConfidentialReport.pdf"); $vbLabelText $csharpLabel Step 2: Encrypt the PDF Using AES Once the PDF is created, encrypt it with AES: byte[] pdfBytes = File.ReadAllBytes(@"C:\Reports\ConfidentialReport.pdf"); using (Aes aes = Aes.Create()) { aes.Key = Encoding.UTF8.GetBytes("abcdefghijklmnop"); aes.IV = new byte[16]; using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV)) using (var ms = new MemoryStream()) { using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write)) { cs.Write(pdfBytes, 0, pdfBytes.Length); } File.WriteAllBytes(@"C:\Reports\ConfidentialReport.encrypted", ms.ToArray()); } } byte[] pdfBytes = File.ReadAllBytes(@"C:\Reports\ConfidentialReport.pdf"); using (Aes aes = Aes.Create()) { aes.Key = Encoding.UTF8.GetBytes("abcdefghijklmnop"); aes.IV = new byte[16]; using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV)) using (var ms = new MemoryStream()) { using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write)) { cs.Write(pdfBytes, 0, pdfBytes.Length); } File.WriteAllBytes(@"C:\Reports\ConfidentialReport.encrypted", ms.ToArray()); } } $vbLabelText $csharpLabel Conclusion Integrating IronPDF with AES encryption allows you to generate dynamic, secure documents that are both accessible and encrypted. Whether developing applications requiring secure document generation or managing sensitive reports, combining IronPDF with solid encryption protects your data. IronPDF simplifies working with PDFs, while AES guarantees that the content remains secure. IronPDF offers a free trial, making it easy for developers to explore its features before committing. If you’re ready to implement IronPDF into your projects, licenses start at $799 for a one-time purchase. 자주 묻는 질문 C#에서 HTML을 PDF로 변환하려면 어떻게 해야 하나요? IronPDF의 RenderHtmlAsPdf 메서드를 사용하여 HTML 문자열을 PDF로 변환할 수 있습니다. 또한 RenderHtmlFileAsPdf를 사용하여 HTML 파일을 PDF로 변환할 수도 있습니다. AES 암호화란 무엇이며 C#에서 어떻게 사용되나요? AES(고급 암호화 표준)는 데이터 보안에 사용되는 대칭 암호화 알고리즘입니다. C#에서 AES 암호화는 System.Security.Cryptography 네임스페이스의 AES 클래스를 사용하여 구현됩니다. AES 인스턴스를 만들고, 키 및 IV 매개 변수를 설정하고, ICryptoTransform 인터페이스를 사용하여 데이터를 암호화 및 해독합니다. AES 암호화에서 사이퍼 블록 체인(CBC) 모드를 사용하면 어떤 이점이 있나요? 암호 블록 체인(CBC) 모드는 동일한 일반 텍스트 블록이 서로 다른 암호 텍스트 블록을 생성하도록 하여 보안을 강화합니다. 이는 초기화 벡터(IV)를 사용하여 블록의 암호화를 체인화함으로써 이루어집니다. C#에서 AES를 사용하여 PDF 문서를 암호화하려면 어떻게 해야 하나요? C#에서 AES를 사용하여 PDF를 암호화하려면 IronPDF를 사용하여 PDF 파일을 처리한 다음, 암호화된 데이터를 새 파일에 다시 쓰기 전에 지정된 키와 IV로 PDF 바이트를 암호화하여 AES 암호화를 적용할 수 있습니다. C# 애플리케이션에서 AES 암호화를 구현하려면 어떤 단계를 거쳐야 하나요? C#에서 AES 암호화를 구현하려면 AES 인스턴스를 생성하고, 키와 IV를 설정하고, 암호화기를 생성하고, MemoryStream 및 CryptoStream를 사용하여 데이터를 변환해야 합니다. C#에서 AES 암호화에 사용자 지정 키와 IV를 사용할 수 있나요? 예, AES 암호화에서는 사용자 지정 키와 IV를 지정하여 보안을 강화할 수 있습니다. 각 암호화 세션에 대해 임의의 값을 생성하는 것이 더 나은 보호를 위해 권장됩니다. 개발자는 C#에서 PDF 문서 보안을 어떻게 강화할 수 있을까요? 개발자는 IronPDF와 AES 암호화를 결합하여 C#에서 PDF 문서 보안을 강화하여 비밀번호 및 디지털 서명을 추가하는 등 PDF를 생성, 편집 및 보호할 수 있습니다. IronPDF는 공유 전 PDF 콘텐츠 보안에 어떤 도움이 되나요? IronPDF는 개발자가 AES를 사용하여 PDF를 암호화할 수 있도록 함으로써 공유 전에 PDF 콘텐츠를 보호할 수 있도록 지원합니다. 이 프로세스에는 데이터 보호를 보장하기 위해 암호화 방법을 사용하여 PDF 파일을 생성, 편집 및 조작하는 작업이 포함됩니다. AES 암호화에서 키 관리가 중요한 이유는 무엇인가요? 암호화된 데이터의 보안은 암호화 키의 비밀성과 강도에 크게 의존하기 때문에 AES 암호화에서는 키 관리가 매우 중요합니다. 적절한 관리는 무단 액세스를 방지합니다. C# 개발자를 위한 IronPDF 라이브러리의 주요 기능은 무엇인가요? IronPDF 라이브러리를 사용하면 C# 개발자가 PDF 문서를 쉽게 생성, 편집 및 조작할 수 있습니다. 병합, 분할 및 암호화를 통한 PDF 보안과 같은 기능을 지원하여 문서 관리 및 보안을 강화합니다. 커티스 차우 지금 바로 엔지니어링 팀과 채팅하세요 기술 문서 작성자 커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다. 커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다. 관련 기사 업데이트됨 12월 11, 2025 Bridging CLI Simplicity & .NET : Using Curl DotNet with IronPDF Jacob Mellor has bridged this gap with CurlDotNet, a library created to bring the familiarity of cURL to the .NET ecosystem. 더 읽어보기 업데이트됨 12월 20, 2025 RandomNumberGenerator C# Using the RandomNumberGenerator C# class can help take your PDF generation and editing projects to the next level 더 읽어보기 업데이트됨 12월 20, 2025 C# String Equals (How it Works for Developers) When combined with a powerful PDF library like IronPDF, switch pattern matching allows you to build smarter, cleaner logic for document processing 더 읽어보기 C# try catch finally (How It Works For Developers)C# HttpClient (How It Works For Dev...
업데이트됨 12월 11, 2025 Bridging CLI Simplicity & .NET : Using Curl DotNet with IronPDF Jacob Mellor has bridged this gap with CurlDotNet, a library created to bring the familiarity of cURL to the .NET ecosystem. 더 읽어보기
업데이트됨 12월 20, 2025 RandomNumberGenerator C# Using the RandomNumberGenerator C# class can help take your PDF generation and editing projects to the next level 더 읽어보기
업데이트됨 12월 20, 2025 C# String Equals (How it Works for Developers) When combined with a powerful PDF library like IronPDF, switch pattern matching allows you to build smarter, cleaner logic for document processing 더 읽어보기