개정판 e05bed4e
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