v3.8.1.0 1、在配置文件中对accessKeyId和accessKeySecret进行加密存储。注意现有配置文件中未加密参数将失效。

This commit is contained in:
wisdomwei201804 2018-04-22 10:05:59 +08:00
parent 9537294d79
commit fdbe4d9dce
3 changed files with 171 additions and 6 deletions

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: : // 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.8.0.0")] [assembly: AssemblyVersion("3.8.1.0")]
[assembly: AssemblyFileVersion("3.8.0.0")] [assembly: AssemblyFileVersion("3.8.1.0")]

View File

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;
@ -121,8 +122,10 @@ namespace net.nutcore.aliddns
i++; i++;
} }
}*/ }*/
accessKeyId.Text = nodes[0].InnerText; accessKeyId.Text = EncryptHelper.AESDecrypt(nodes[0].InnerText);
accessKeySecret.Text = nodes[1].InnerText; accessKeySecret.Text = EncryptHelper.AESDecrypt(nodes[1].InnerText);
//accessKeyId.Text = nodes[0].InnerText;
//accessKeySecret.Text = nodes[1].InnerText;
recordId.Text = nodes[2].InnerText; recordId.Text = nodes[2].InnerText;
fullDomainName.Text = nodes[3].InnerText; fullDomainName.Text = nodes[3].InnerText;
label_nextUpdateSeconds.Text = newSeconds.Text = nodes[4].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"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "任何值都不能为空无法填写请输入null或0" + "\r\n");
return false; return false;
} }
string accessKeyId_encrypt = EncryptHelper.AESEncrypt(accessKeyId.Text);
string accessKeySecret_encrypt = EncryptHelper.AESEncrypt(accessKeySecret.Text);
string ExePath = System.AppDomain.CurrentDomain.BaseDirectory; string ExePath = System.AppDomain.CurrentDomain.BaseDirectory;
string config_file = ExePath + "aliddns_config.xml"; string config_file = ExePath + "aliddns_config.xml";
XmlTextWriter textWriter = new XmlTextWriter(config_file, null); XmlTextWriter textWriter = new XmlTextWriter(config_file, null);
@ -170,11 +175,11 @@ namespace net.nutcore.aliddns
textWriter.WriteStartElement("Config"); //设置项目开始 textWriter.WriteStartElement("Config"); //设置项目开始
textWriter.WriteStartElement("AccessKeyID", ""); textWriter.WriteStartElement("AccessKeyID", "");
textWriter.WriteString(accessKeyId.Text); textWriter.WriteString(accessKeyId_encrypt);
textWriter.WriteEndElement(); textWriter.WriteEndElement();
textWriter.WriteStartElement("AccessKeySecret", ""); textWriter.WriteStartElement("AccessKeySecret", "");
textWriter.WriteString(accessKeySecret.Text); textWriter.WriteString(accessKeySecret_encrypt);
textWriter.WriteEndElement(); textWriter.WriteEndElement();
textWriter.WriteStartElement("RecordID", ""); textWriter.WriteStartElement("RecordID", "");
@ -700,4 +705,161 @@ namespace net.nutcore.aliddns
} }
} }
/// <summary>
/// 加密工具类
/// </summary>
public class EncryptHelper
{
//默认密钥
private static string AESKey = "[45/*YUIdse..e;]";
private static string DESKey = "[&HdN72]";
/// <summary>
/// AES加密
/// </summary>
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);
}
/// <summary>
/// AES解密
/// </summary>
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;
}
}
/// <summary>
/// DES加密
/// </summary>
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);
}
/// <summary>
/// DES解密
/// </summary>
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("-", "");
}
/// <summary>
/// base64编码
/// </summary>
/// <returns></returns>
public static string Base64Encode(string value)
{
string result = Convert.ToBase64String(Encoding.Default.GetBytes(value));
return result;
}
/// <summary>
/// base64解码
/// </summary>
/// <returns></returns>
public static string Base64Decode(string value)
{
string result = Encoding.Default.GetString(Convert.FromBase64String(value));
return result;
}
}
} }

View File

@ -1,3 +1,6 @@
v3.8.1.0
1、在配置文件中对accessKeyId和accessKeySecret进行加密存储。注意现有配置文件中未加密参数将失效。
v3.8.0.0 v3.8.0.0
1、增加TTL参数。2、修复代码BUG。 1、增加TTL参数。2、修复代码BUG。