From fdbe4d9dce685dbbc8c03c29bde7c3a764dd7507 Mon Sep 17 00:00:00 2001 From: wisdomwei201804 Date: Sun, 22 Apr 2018 10:05:59 +0800 Subject: [PATCH] =?UTF-8?q?v3.8.1.0=20=201=E3=80=81=E5=9C=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=AD=E5=AF=B9accessKeyId?= =?UTF-8?q?=E5=92=8CaccessKeySecret=E8=BF=9B=E8=A1=8C=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E3=80=82=E6=B3=A8=E6=84=8F=E7=8E=B0=E6=9C=89?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=AD=E6=9C=AA=E5=8A=A0?= =?UTF-8?q?=E5=AF=86=E5=8F=82=E6=95=B0=E5=B0=86=E5=A4=B1=E6=95=88=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Properties/AssemblyInfo.cs | 4 +- .../net.nutcore.aliddns/main.cs | 170 +++++++++++++++++- .../net.nutcore.aliddns/updateinfo.txt | 3 + 3 files changed, 171 insertions(+), 6 deletions(-) diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Properties/AssemblyInfo.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Properties/AssemblyInfo.cs index 106339d..e3862fd 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Properties/AssemblyInfo.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.8.0.0")] -[assembly: AssemblyFileVersion("3.8.0.0")] +[assembly: AssemblyVersion("3.8.1.0")] +[assembly: AssemblyFileVersion("3.8.1.0")] diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/main.cs b/net.nutcore.aliddns/net.nutcore.aliddns/main.cs index a059a33..49429fd 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/main.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/main.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Net; +using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -121,8 +122,10 @@ namespace net.nutcore.aliddns i++; } }*/ - accessKeyId.Text = nodes[0].InnerText; - accessKeySecret.Text = nodes[1].InnerText; + accessKeyId.Text = EncryptHelper.AESDecrypt(nodes[0].InnerText); + accessKeySecret.Text = EncryptHelper.AESDecrypt(nodes[1].InnerText); + //accessKeyId.Text = nodes[0].InnerText; + //accessKeySecret.Text = nodes[1].InnerText; recordId.Text = nodes[2].InnerText; fullDomainName.Text = nodes[3].InnerText; label_nextUpdateSeconds.Text = newSeconds.Text = nodes[4].InnerText; @@ -159,6 +162,8 @@ namespace net.nutcore.aliddns textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "任何值都不能为空!无法填写请输入null或0!" + "\r\n"); return false; } + string accessKeyId_encrypt = EncryptHelper.AESEncrypt(accessKeyId.Text); + string accessKeySecret_encrypt = EncryptHelper.AESEncrypt(accessKeySecret.Text); string ExePath = System.AppDomain.CurrentDomain.BaseDirectory; string config_file = ExePath + "aliddns_config.xml"; XmlTextWriter textWriter = new XmlTextWriter(config_file, null); @@ -170,11 +175,11 @@ namespace net.nutcore.aliddns textWriter.WriteStartElement("Config"); //设置项目开始 textWriter.WriteStartElement("AccessKeyID", ""); - textWriter.WriteString(accessKeyId.Text); + textWriter.WriteString(accessKeyId_encrypt); textWriter.WriteEndElement(); textWriter.WriteStartElement("AccessKeySecret", ""); - textWriter.WriteString(accessKeySecret.Text); + textWriter.WriteString(accessKeySecret_encrypt); textWriter.WriteEndElement(); textWriter.WriteStartElement("RecordID", ""); @@ -700,4 +705,161 @@ namespace net.nutcore.aliddns } } + + /// + /// 加密工具类 + /// + public class EncryptHelper + { + //默认密钥 + private static string AESKey = "[45/*YUIdse..e;]"; + private static string DESKey = "[&HdN72]"; + + /// + /// AES加密 + /// + public static string AESEncrypt(string value, string _aeskey = null) + { + if (string.IsNullOrEmpty(_aeskey)) + { + _aeskey = AESKey; + } + + byte[] keyArray = Encoding.UTF8.GetBytes(_aeskey); + byte[] toEncryptArray = Encoding.UTF8.GetBytes(value); + + RijndaelManaged rDel = new RijndaelManaged(); + rDel.Key = keyArray; + rDel.Mode = CipherMode.ECB; + rDel.Padding = PaddingMode.PKCS7; + + ICryptoTransform cTransform = rDel.CreateEncryptor(); + byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); + + return Convert.ToBase64String(resultArray, 0, resultArray.Length); + } + + /// + /// AES解密 + /// + public static string AESDecrypt(string value, string _aeskey = null) + { + try + { + if (string.IsNullOrEmpty(_aeskey)) + { + _aeskey = AESKey; + } + byte[] keyArray = Encoding.UTF8.GetBytes(_aeskey); + byte[] toEncryptArray = Convert.FromBase64String(value); + + RijndaelManaged rDel = new RijndaelManaged(); + rDel.Key = keyArray; + rDel.Mode = CipherMode.ECB; + rDel.Padding = PaddingMode.PKCS7; + + ICryptoTransform cTransform = rDel.CreateDecryptor(); + byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); + + return Encoding.UTF8.GetString(resultArray); + } + catch + { + return string.Empty; + } + } + + /// + /// DES加密 + /// + public static string DESEncrypt(string value, string _deskey = null) + { + if (string.IsNullOrEmpty(_deskey)) + { + _deskey = DESKey; + } + + byte[] keyArray = Encoding.UTF8.GetBytes(_deskey); + byte[] toEncryptArray = Encoding.UTF8.GetBytes(value); + + DESCryptoServiceProvider rDel = new DESCryptoServiceProvider(); + rDel.Key = keyArray; + rDel.Mode = CipherMode.ECB; + rDel.Padding = PaddingMode.PKCS7; + + ICryptoTransform cTransform = rDel.CreateEncryptor(); + byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); + + return Convert.ToBase64String(resultArray, 0, resultArray.Length); + } + + /// + /// DES解密 + /// + public static string DESDecrypt(string value, string _deskey = null) + { + try + { + if (string.IsNullOrEmpty(_deskey)) + { + _deskey = DESKey; + } + byte[] keyArray = Encoding.UTF8.GetBytes(_deskey); + byte[] toEncryptArray = Convert.FromBase64String(value); + + DESCryptoServiceProvider rDel = new DESCryptoServiceProvider(); + rDel.Key = keyArray; + rDel.Mode = CipherMode.ECB; + rDel.Padding = PaddingMode.PKCS7; + + ICryptoTransform cTransform = rDel.CreateDecryptor(); + byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); + + return Encoding.UTF8.GetString(resultArray); + } + catch + { + return string.Empty; + } + } + + public static string MD5(string value) + { + byte[] result = Encoding.UTF8.GetBytes(value); + MD5 md5 = new MD5CryptoServiceProvider(); + byte[] output = md5.ComputeHash(result); + return BitConverter.ToString(output).Replace("-", ""); + } + + public static string HMACMD5(string value, string hmacKey) + { + HMACSHA1 hmacsha1 = new HMACSHA1(Encoding.UTF8.GetBytes(hmacKey)); + byte[] result = System.Text.Encoding.UTF8.GetBytes(value); + byte[] output = hmacsha1.ComputeHash(result); + + + return BitConverter.ToString(output).Replace("-", ""); + } + + /// + /// base64编码 + /// + /// + public static string Base64Encode(string value) + { + string result = Convert.ToBase64String(Encoding.Default.GetBytes(value)); + return result; + } + /// + /// base64解码 + /// + /// + public static string Base64Decode(string value) + { + string result = Encoding.Default.GetString(Convert.FromBase64String(value)); + return result; + } + + + } } diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/updateinfo.txt b/net.nutcore.aliddns/net.nutcore.aliddns/updateinfo.txt index eb54086..753cb8e 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/updateinfo.txt +++ b/net.nutcore.aliddns/net.nutcore.aliddns/updateinfo.txt @@ -1,3 +1,6 @@ +v3.8.1.0 +1ļжaccessKeyIdaccessKeySecretмܴ洢עļδܲʧЧ + v3.8.0.0 1TTL2޸BUG