프로젝트

일반

사용자정보

개정판 e05bed4e

IDe05bed4e5b655047d3c494611c9fcba1f48af299
상위 959b3ef2
하위 dd00cda0, f69db4e1

김동진이(가) 5년 이상 전에 추가함

issue #000 connectionString App.Config -> ini move , daelim final service setupfile add

Change-Id: I62de9b0cdbd79173f7da663a4ea897433de2849e

차이점 보기:

FinalService/KCOM_FinalService/CommonLib/Common.cs
3 3
using System.IO;
4 4
using System.Linq;
5 5
using System.Runtime.InteropServices;
6
using System.Security.Cryptography;
6 7
using System.Text;
7 8
using System.Threading.Tasks;
8 9

  
......
11 12
    public class Common
12 13
    {
13 14
        [DllImport("kernel32")]
14
        public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
15
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
15 16

  
16 17
        public static string AppDataFolder
17 18
        {
......
20 21
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS");
21 22
            }
22 23
        }
24
        public static string GetConfigString(string section, string key, string def)
25
        {
26
            System.Text.StringBuilder strbuilder = new System.Text.StringBuilder(512);
27
            GetPrivateProfileString(section, key, def, strbuilder, 512, Path.Combine(AppDataFolder, "FinalService.ini"));
28
            return strbuilder.ToString();
29
        }
30

  
31
        public static string GetConnectionString()
32
        {
33
            System.Text.StringBuilder strbuilder = new System.Text.StringBuilder(512);
34
            GetPrivateProfileString("ConnectionString", "STRING", "", strbuilder, 512, Path.Combine(AppDataFolder, "FinalService.ini"));
35
            return Decrypt(strbuilder.ToString(), "Doftech1073#");
36
        }
37
        private static string Decrypt(string textToDecrypt, string key)
38
        {
39
            RijndaelManaged rijndaelCipher = new RijndaelManaged();
40
            rijndaelCipher.Mode = CipherMode.CBC;
41
            rijndaelCipher.Padding = PaddingMode.PKCS7;
42
            rijndaelCipher.KeySize = 128;
43
            rijndaelCipher.BlockSize = 128;
44

  
45
            byte[] encryptedData = Convert.FromBase64String(textToDecrypt);
46
            byte[] pwdBytes = Encoding.UTF8.GetBytes(key);
47
            byte[] keyBytes = new byte[16];
48

  
49
            int len = pwdBytes.Length;
50
            if (len > keyBytes.Length)
51
            {
52
                len = keyBytes.Length;
53
            }
54

  
55
            Array.Copy(pwdBytes, keyBytes, len);
56
            rijndaelCipher.Key = keyBytes;
57
            rijndaelCipher.IV = keyBytes;
58

  
59
            byte[] plainText = rijndaelCipher.CreateDecryptor().TransformFinalBlock(encryptedData, 0, encryptedData.Length);
60
            return Encoding.UTF8.GetString(plainText);
61
        }
23 62
    }
24 63
}

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)