C# AES128 암호화 복호화 소스
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Security.Cryptography; using System.IO; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { String s = "TEST08"; String key = "nfaator!plaeemo!"; Console.WriteLine(Encrypt(s, key)); Console.WriteLine(Decrypt(Encrypt(s, key), key)); } private static string Encrypt(string s, string key) { StringBuilder sbResult = new StringBuilder(); byte[] KeyArray = UTF8Encoding.UTF8.GetBytes(key); byte[] EncryptArray = UTF8Encoding.UTF8.GetBytes(s); RijndaelManaged Rdel = new RijndaelManaged(); Rdel.Mode = CipherMode.ECB; Rdel.Padding = PaddingMode.Zeros; Rdel.Key = KeyArray; ICryptoTransform CtransForm = Rdel.CreateEncryptor(); byte[] ResultArray = CtransForm.TransformFinalBlock(EncryptArray, 0, EncryptArray.Length); foreach (byte b in ResultArray) { sbResult.AppendFormat("{0:x2}", b); } return sbResult.ToString(); } private static string Decrypt(string s, string key) { byte[] KeyArray = UTF8Encoding.UTF8.GetBytes(key); byte[] EncryptArray = HexToByte(s); RijndaelManaged Rdel = new RijndaelManaged(); Rdel.Mode = CipherMode.ECB; Rdel.Padding = PaddingMode.Zeros; Rdel.Key = KeyArray; ICryptoTransform CtransForm = Rdel.CreateDecryptor(); byte[] ResultArray = CtransForm.TransformFinalBlock(EncryptArray, 0, EncryptArray.Length); return UTF8Encoding.UTF8.GetString(ResultArray); } private static byte[] HexToByte(string msg) { msg = msg.Replace(" ", ""); byte[] comBuffer = new byte[msg.Length / 2]; for(int i = 0; i < msg.Length; i+=2) { try { comBuffer[i / 2] = (byte)Convert.ToByte(msg.Substring(i, 2), 16); } catch(ArgumentOutOfRangeException ex) { Console.WriteLine(ex.ToString()); } } return comBuffer; } } }
[출처] C# JAVA AES128 암호화 복호화 소스|작성자 실버캐슬
'Dev Language > C#' 카테고리의 다른 글
C# 디컴파일 프로그램 (0) | 2020.02.19 |
---|---|
AES, SHA 암호화 3, C# (0) | 2017.03.30 |
외부에서 호스팅업체 MYSQL 접근하기(+ DLL 포함 컴파일) (0) | 2016.10.05 |
윈도우 플랫폼 체크 (0) | 2015.12.31 |
Mac Address Changer(맥 어드레스 변경) (0) | 2015.12.30 |