프로젝트

일반

사용자정보

개정판 91c7a82a

ID91c7a82a175f8b367fa693f7a7b910badaa0c05f
상위 d41a758d
하위 da8624d4, 2e1cd7b8

gaqhf 이(가) 약 5년 전에 추가함

dev issue #000 : add license

Change-Id: I74d328bb97d1c3116562fad3deb0160e23a13180

차이점 보기:

DTI_PID/DateLicense/licenses.licx
1
H+9APzieMmqSucbRbyCaeA==
DTI_PID/Perpetuallicense/licenses.licx
1
fTkVJR8OrFMaAqu8ooakRQ==
DTI_PID/SPPIDConverter/License.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Security.Cryptography;
7
using System.IO;
8
using Microsoft.Win32;
9
using System.Net.NetworkInformation;
10

  
11
namespace DOFTECH.License
12
{
13
    public static class License
14
    {
15
        public static bool IsEnabled()
16
        {
17
            bool result = false;
18
            string path = string.Empty;
19

  
20
            try
21
            {
22
                RegistryKey key = Registry.LocalMachine;
23
                RegistryKey software = key.OpenSubKey("SOFTWARE");
24
                RegistryKey DOFTECH = software.OpenSubKey("DOFTECH");
25
                RegistryKey SPPIDConverter = DOFTECH.OpenSubKey("SPPIDConverter");
26
                path = SPPIDConverter.GetValue("path") + "licenses.licx";
27
                if (File.Exists(path))
28
                {
29
                    string data = File.ReadAllText(path);
30
                    data = Crypt.decrypt(data, "dof1073#");
31
                    if (data.StartsWith("Date:"))
32
                    {
33
                        data = data.Remove(0, "Date:".Length);
34

  
35
                        if (string.IsNullOrEmpty(data))
36
                        {
37
                            data = "Date:" + DateTime.Today.ToShortDateString();
38
                            data = Crypt.encrypt(data, "dof1073#");
39
                            File.WriteAllText(path, data);
40
                            result = true;
41
                        }
42
                        else
43
                        {
44
                            DateTime dataTime = DateTime.MinValue;
45
                            DateTime currentTime = DateTime.Now;
46
                            if (DateTime.TryParse(data, out dataTime) && DateTime.Compare(dataTime.AddDays(7), currentTime) >= 0)
47
                                result = true;
48
                        }
49
                    }
50
                    else if (data.StartsWith("Absolute:"))
51
                    {
52
                        data = data.Remove(0, "Absolute:".Length);
53
                        string macAddress = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString();
54
                        if (string.IsNullOrEmpty(data))
55
                        {
56
                            data = "Absolute:" + macAddress;
57
                            data = Crypt.encrypt(data, "dof1073#");
58
                            File.WriteAllText(path, data);
59
                            result = true;
60
                        }
61
                        else if (macAddress == data)
62
                            result = true;
63
                    }
64
                }
65
            }
66
            catch (Exception ex)
67
            {
68

  
69
            }
70

  
71
            return result;
72
        }
73

  
74
        public static string SHA256Hash(string data)
75
        {
76

  
77
            SHA256 sha = new SHA256Managed();
78
            byte[] hash = sha.ComputeHash(Encoding.ASCII.GetBytes(data));
79
            StringBuilder stringBuilder = new StringBuilder();
80
            foreach (byte b in hash)
81
            {
82
                stringBuilder.AppendFormat("{0:x2}", b);
83
            }
84
            return stringBuilder.ToString();
85
        }
86

  
87
        private static void CreateDateLicenseFile()
88
        {
89
            string path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\[Date]licenses.licx";
90
            string data = "Date:";
91
            using (StreamWriter sw = File.CreateText(path))
92
            {
93
                data = Crypt.encrypt(data, "dof1073#");
94
                sw.Write(data);
95
                sw.Close();
96
                sw.Dispose();
97
            }
98
        }
99

  
100
        private static void CreateAbsoluteLicenseFile()
101
        {
102
            string path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\[Absolute]licenses.licx";
103
            string data = "Absolute:";
104
            using (StreamWriter sw = File.CreateText(path))
105
            {
106
                data = Crypt.encrypt(data, "dof1073#");
107
                sw.Write(data);
108
                sw.Close();
109
                sw.Dispose();
110
            }
111
        }
112
    }
113

  
114
    class Crypt
115
    {
116
        public static String encrypt(String text, String password)
117
        {
118
            RijndaelManaged RijndaelCipher = new RijndaelManaged();
119
            byte[] plainText = Encoding.UTF8.GetBytes(text);
120
            byte[] salt = Encoding.UTF8.GetBytes(password);
121
            PasswordDeriveBytes secretKey = new PasswordDeriveBytes(password, salt);
122
            ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(secretKey.GetBytes(32), secretKey.GetBytes(16));
123
            MemoryStream memoryStream = new MemoryStream();
124
            CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write);
125
            cryptoStream.Write(plainText, 0, plainText.Length);     // 암호화 시작
126
            cryptoStream.FlushFinalBlock();
127
            byte[] cryptBytes = memoryStream.ToArray();
128
            // 스트림을 닫습니다.
129
            memoryStream.Close();
130
            cryptoStream.Close();
131
            String cryptResult = Convert.ToBase64String(cryptBytes);
132
            return cryptResult;     // 암호화 문자열 리턴.
133
        }
134
        public static String decrypt(String text, String password)
135
        {
136
            RijndaelManaged RijndaelCipher = new RijndaelManaged();
137
            byte[] encryptData = Convert.FromBase64String(text);
138
            byte[] salt = Encoding.UTF8.GetBytes(password);
139
            PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(password, salt);
140
            ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
141
            MemoryStream memoryStream = new MemoryStream(encryptData);
142
            CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);
143
            byte[] PlainText = new byte[encryptData.Length];
144
            // 복호화 시작
145
            int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);
146
            memoryStream.Close();
147
            cryptoStream.Close();
148
            // 복호화된 데이터를 문자열로 바꾼다.
149
            string DecryptedData = Encoding.UTF8.GetString(PlainText, 0, DecryptedCount);
150
            // 최종 결과 리턴
151
            return DecryptedData;
152
        }
153
    }
154
}
DTI_PID/SPPIDConverter/SPPIDConverter.csproj
137 137
    <Compile Include="Form\ID2DBSetting.Designer.cs">
138 138
      <DependentUpon>ID2DBSetting.cs</DependentUpon>
139 139
    </Compile>
140
    <Compile Include="License.cs" />
140 141
    <Compile Include="OPC\AutoModeling_OPC.cs" />
141 142
    <Compile Include="BaseModel\ChildSymbol.cs" />
142 143
    <Compile Include="BaseModel\Document.cs" />
DTI_PID/SPPIDConverter/Wrapper/SPPIDConverterWrapper.cs
24 24
using Microsoft.Win32;
25 25
using Ingr.RAD2D;
26 26
using System.Reflection;
27
using DOFTECH;
27 28

  
28 29
namespace Converter.SPPID.Wrapper
29 30
{
......
125 126
            {
126 127
                RegistryKey key = Registry.LocalMachine;
127 128
                RegistryKey software = key.OpenSubKey("SOFTWARE");
128
                RegistryKey DOFTECH = software.OpenSubKey("DOFTECH");
129
                if (DOFTECH != null)
129
                RegistryKey Doftech = software.OpenSubKey("DOFTECH");
130
                if (Doftech != null)
130 131
                {
131
                    RegistryKey SPPIDConverter = DOFTECH.OpenSubKey("SPPIDConverter");
132
                    if (SPPIDConverter != null)
132
                    RegistryKey SPPIDConverter = Doftech.OpenSubKey("SPPIDConverter");
133
                    if (SPPIDConverter != null && DOFTECH.License.License.IsEnabled())
133 134
                    {
134 135
                        autoModelingDllPath = SPPIDConverter.GetValue("path") + @"SPPIDConverter.dll";
135 136
#if DEBUG

내보내기 Unified diff

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