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