프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / CommonLib / Common.cs @ 35afe17c

이력 | 보기 | 이력해설 | 다운로드 (2.73 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.IO;
4
using System.Linq;
5
using System.Runtime.InteropServices;
6
using System.Security.Cryptography;
7
using System.Text;
8
using System.Threading.Tasks;
9

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

    
17
        public static string AppDataFolder
18
        {
19
            get
20
            {
21
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS");
22
            }
23
        }
24

    
25
        /// <summary>
26
        /// Client 에 설치된 MARKUS.ini 를 참조.
27
        /// </summary>
28
        /// <param name="section"></param>
29
        /// <param name="key"></param>
30
        /// <param name="def"></param>
31
        /// <returns></returns>
32
        public static string GetConfigString(string section, string key, string def)
33
        {
34
            System.Text.StringBuilder strbuilder = new System.Text.StringBuilder(512);
35
            GetPrivateProfileString(section, key, def, strbuilder, 512, Path.Combine(AppDataFolder, "MARKUS.ini"));
36
            return strbuilder.ToString();
37
        }
38

    
39
        /// <summary>
40
        /// 서버에 설치된 Service ini 의 Connection String 을 참조
41
        /// </summary>
42
        /// <returns></returns>
43
        public static string GetConnectionString()
44
        {
45
            System.Text.StringBuilder strbuilder = new System.Text.StringBuilder(512);
46
            GetPrivateProfileString("ConnectionString", "STRING", "", strbuilder, 512, Path.Combine(AppDataFolder, "FinalService.ini"));
47
            return Decrypt(strbuilder.ToString(), "Doftech1073#");
48
        }
49
        private static string Decrypt(string textToDecrypt, string key)
50
        {
51
            RijndaelManaged rijndaelCipher = new RijndaelManaged();
52
            rijndaelCipher.Mode = CipherMode.CBC;
53
            rijndaelCipher.Padding = PaddingMode.PKCS7;
54
            rijndaelCipher.KeySize = 128;
55
            rijndaelCipher.BlockSize = 128;
56

    
57
            byte[] encryptedData = Convert.FromBase64String(textToDecrypt);
58
            byte[] pwdBytes = Encoding.UTF8.GetBytes(key);
59
            byte[] keyBytes = new byte[16];
60

    
61
            int len = pwdBytes.Length;
62
            if (len > keyBytes.Length)
63
            {
64
                len = keyBytes.Length;
65
            }
66

    
67
            Array.Copy(pwdBytes, keyBytes, len);
68
            rijndaelCipher.Key = keyBytes;
69
            rijndaelCipher.IV = keyBytes;
70

    
71
            byte[] plainText = rijndaelCipher.CreateDecryptor().TransformFinalBlock(encryptedData, 0, encryptedData.Length);
72
            return Encoding.UTF8.GetString(plainText);
73
        }
74
    }
75
}
클립보드 이미지 추가 (최대 크기: 500 MB)