diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/EncryptHelper.cs b/net.nutcore.aliddns/net.nutcore.aliddns/EncryptHelper.cs new file mode 100644 index 0000000..2a9a63a --- /dev/null +++ b/net.nutcore.aliddns/net.nutcore.aliddns/EncryptHelper.cs @@ -0,0 +1,161 @@ +using System; +using System.Security.Cryptography; +using System.Text; + +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/Form_main.Designer.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs index 2c8c1e3..a84e46f 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs @@ -189,13 +189,13 @@ // // label_nextUpdateSeconds // - this.label_nextUpdateSeconds.AutoSize = true; this.label_nextUpdateSeconds.ForeColor = System.Drawing.Color.Red; - this.label_nextUpdateSeconds.Location = new System.Drawing.Point(97, 99); + this.label_nextUpdateSeconds.Location = new System.Drawing.Point(87, 99); this.label_nextUpdateSeconds.Name = "label_nextUpdateSeconds"; - this.label_nextUpdateSeconds.Size = new System.Drawing.Size(17, 12); + this.label_nextUpdateSeconds.Size = new System.Drawing.Size(30, 12); this.label_nextUpdateSeconds.TabIndex = 3; this.label_nextUpdateSeconds.Text = "60"; + this.label_nextUpdateSeconds.TextAlign = System.Drawing.ContentAlignment.TopRight; // // updateNow // diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs index fb89161..69c0971 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs @@ -6,7 +6,6 @@ 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; @@ -914,161 +913,4 @@ 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/Properties/AssemblyInfo.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Properties/AssemblyInfo.cs index a360133..a82c5b6 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.3.5")] -[assembly: AssemblyFileVersion("3.8.3.5")] +[assembly: AssemblyVersion("3.8.4.0")] +[assembly: AssemblyFileVersion("3.8.4.0")] diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj b/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj index e5014ab..a91879d 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj +++ b/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj @@ -88,6 +88,7 @@ + Form @@ -109,7 +110,6 @@ - Form_About.cs @@ -149,7 +149,9 @@ - + + PreserveNewest + @@ -172,7 +174,8 @@ - copy "$(SolutionDir)net.nutcore.aliddns\updateinfo.txt" "$(TargetDir)" + +