markus / FinalService / KCOM_FinalService / CommonLib / Common.cs @ ad3c4ac3
이력 | 보기 | 이력해설 | 다운로드 (2.34 KB)
1 | cd172bb8 | djkim | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.IO; |
||
4 | using System.Linq; |
||
5 | using System.Runtime.InteropServices; |
||
6 | e05bed4e | djkim | using System.Security.Cryptography; |
7 | cd172bb8 | djkim | using System.Text; |
8 | using System.Threading.Tasks; |
||
9 | |||
10 | namespace CommonLib |
||
11 | { |
||
12 | public class Common |
||
13 | { |
||
14 | [DllImport("kernel32")] |
||
15 | e05bed4e | djkim | private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); |
16 | cd172bb8 | djkim | |
17 | public static string AppDataFolder |
||
18 | { |
||
19 | get |
||
20 | { |
||
21 | return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS"); |
||
22 | } |
||
23 | } |
||
24 | e05bed4e | djkim | 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 | } |
||
62 | cd172bb8 | djkim | } |
63 | } |