diff --git a/OSTLibrary/Securities/AES256.cs b/OSTLibrary/Securities/AES256.cs index 0cc70dd..11b55de 100644 --- a/OSTLibrary/Securities/AES256.cs +++ b/OSTLibrary/Securities/AES256.cs @@ -1,62 +1,54 @@ -using System; -using System.Text; +using System.Text; using System.Security.Cryptography; using System.IO; namespace OSTLibrary.Securities { - class AESEncrypt + // 참조사이트-https://h5bak.tistory.com/148 + public static class AES256 { - private SHA256Managed sha256Managed = new SHA256Managed(); - private RijndaelManaged aes = new RijndaelManaged(); - - public AESEncrypt() + private static string key = "qlalfqjsgh@djfuqekGG"; + private static SHA256Managed sha256Managed = new SHA256Managed(); + private static RijndaelManaged aes = new RijndaelManaged() { - aes.KeySize = 256; - aes.BlockSize = 128; - aes.Mode = CipherMode.CBC; - aes.Padding = PaddingMode.PKCS7; - } + KeySize = 256, + BlockSize = 128, + Mode = CipherMode.CBC, + Padding = PaddingMode.PKCS7 + }; - - //AES_256 암호화 - public byte[] AESEncrypt256(byte[] encryptData, String password) + public static byte[] Encrypt(byte[] data) { // Salt는 비밀번호의 길이를 SHA256 해쉬값으로 한다. - var salt = sha256Managed.ComputeHash(Encoding.UTF8.GetBytes(password.Length.ToString())); - Console.WriteLine("Salt(Base64) : " + Convert.ToBase64String(salt)); + var salt = sha256Managed.ComputeHash(Encoding.UTF8.GetBytes(key.Length.ToString())); //PBKDF2(Password-Based Key Derivation Function) //반복은 65535번 - var PBKDF2Key = new Rfc2898DeriveBytes(password, salt, 65535, HashAlgorithmName.SHA256); + var PBKDF2Key = new Rfc2898DeriveBytes(key, salt, 65535, HashAlgorithmName.SHA256); var secretKey = PBKDF2Key.GetBytes(aes.KeySize / 8); var iv = PBKDF2Key.GetBytes(aes.BlockSize / 8); - Console.WriteLine("SecretKey(Base64) : " + Convert.ToBase64String(secretKey)); - Console.WriteLine("IV(Base64) : " + Convert.ToBase64String(iv)); - byte[] xBuff = null; using (var ms = new MemoryStream()) { using (var cs = new CryptoStream(ms, aes.CreateEncryptor(secretKey, iv), CryptoStreamMode.Write)) { - cs.Write(encryptData, 0, encryptData.Length); + cs.Write(data, 0, data.Length); } xBuff = ms.ToArray(); } return xBuff; } - //AES_256 복호화 - public byte[] AESDecrypt256(byte[] decryptData, String password) + public static byte[] Decrypt(byte[] data) { // Salt는 비밀번호의 길이를 SHA256 해쉬값으로 한다. - var salt = sha256Managed.ComputeHash(Encoding.UTF8.GetBytes(password.Length.ToString())); + var salt = sha256Managed.ComputeHash(Encoding.UTF8.GetBytes(key.Length.ToString())); //PBKDF2(Password-Based Key Derivation Function) //반복은 65535번 - var PBKDF2Key = new Rfc2898DeriveBytes(password, salt, 65535, HashAlgorithmName.SHA256); + var PBKDF2Key = new Rfc2898DeriveBytes(key, salt, 65535, HashAlgorithmName.SHA256); var secretKey = PBKDF2Key.GetBytes(aes.KeySize / 8); var iv = PBKDF2Key.GetBytes(aes.BlockSize / 8); @@ -65,30 +57,11 @@ public byte[] AESDecrypt256(byte[] decryptData, String password) { using (var cs = new CryptoStream(ms, aes.CreateDecryptor(secretKey, iv), CryptoStreamMode.Write)) { - cs.Write(decryptData, 0, decryptData.Length); + cs.Write(data, 0, data.Length); } xBuff = ms.ToArray(); } return xBuff; } } - // 참조사이트-https://h5bak.tistory.com/148 - public static class AES256 - { - public static byte[] Encrypt(byte[] data, string key) - { - AESEncrypt aes = new AESEncrypt(); - return aes.AESEncrypt256(data, key); - } - public static string Encrypt(string data, string key) - => Encoding.Default.GetString(Encrypt(Encoding.Default.GetBytes(data), key)); - - public static byte[] Decrypt(byte[] data, string key) - { - AESEncrypt aes = new AESEncrypt(); - return aes.AESDecrypt256(data, key); - } - public static string Decrypt(string data, string key) - => Encoding.Default.GetString(Decrypt(Encoding.Default.GetBytes(data), key)); - } } \ No newline at end of file diff --git a/Server/Classes/Client.cs b/Server/Classes/Client.cs index ac039e7..707b267 100644 --- a/Server/Classes/Client.cs +++ b/Server/Classes/Client.cs @@ -270,6 +270,7 @@ public void Send(Packet packet) ns.Flush(); } } + void Log(string type, string content) { Program.Log(employee.id, type, content);