diff --git a/CoreCms.Net.Configuration/AppSettingsConstVars.cs b/CoreCms.Net.Configuration/AppSettingsConstVars.cs
index dc79b8b8..d78feba7 100644
--- a/CoreCms.Net.Configuration/AppSettingsConstVars.cs
+++ b/CoreCms.Net.Configuration/AppSettingsConstVars.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using SqlSugar.Extensions;
@@ -71,8 +72,8 @@ namespace CoreCms.Net.Configuration
#region Jwt授权配置================================================================================
- public static readonly string JwtConfigSecretKey = AppSettingsHelper.GetContent("JwtConfig", "SecretKey");
- public static readonly string JwtConfigIssuer = AppSettingsHelper.GetContent("JwtConfig", "Issuer");
+ public static readonly string JwtConfigSecretKey = AppSettingsHelper.GetContent("JwtConfig", "SecretKey") + AppSettingsHelper.GetMachineRandomKey(DbSqlConnection + AppSettingsHelper.GetMACIp(true));
+ public static readonly string JwtConfigIssuer = !string.IsNullOrEmpty(AppSettingsHelper.GetContent("JwtConfig", "Issuer")) ? AppSettingsHelper.GetContent("JwtConfig", "Issuer") : AppSettingsHelper.GetHostName();
public static readonly string JwtConfigAudience = AppSettingsHelper.GetContent("JwtConfig", "Audience");
#endregion
diff --git a/CoreCms.Net.Configuration/AppSettingsHelper.cs b/CoreCms.Net.Configuration/AppSettingsHelper.cs
index 4545ed73..4916d5cd 100644
--- a/CoreCms.Net.Configuration/AppSettingsHelper.cs
+++ b/CoreCms.Net.Configuration/AppSettingsHelper.cs
@@ -1,6 +1,10 @@
using System;
using System.Linq;
+using System.Net.NetworkInformation;
+using System.Reflection.PortableExecutable;
+using System.Security.Cryptography;
+using System.Text;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Newtonsoft.Json.Linq;
@@ -42,5 +46,100 @@ namespace CoreCms.Net.Configuration
return "";
}
+
+
+
+ ///
+ /// ȡ MAC ַ
+ ///
+ /// ǷֻΪȡkeyһͬͬд
+ ///
+ public static string GetMACIp(bool needToken)
+ {
+ //ؼϢ
+ IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
+ //ȡ
+ NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
+
+ //ȡ
+ var HostName = computerProperties.HostName;
+ //ȡ
+ var DomainName = computerProperties.DomainName;
+
+ if (nics == null || nics.Length < 1)
+ {
+ return "";
+ }
+
+ var MACIp = needToken ? HostName + DomainName : "";
+ foreach (NetworkInterface adapter in nics)
+ {
+ var adapterName = adapter.Name;
+
+ var adapterDescription = adapter.Description;
+ var NetworkInterfaceType = adapter.NetworkInterfaceType;
+ if (adapterName == "" || needToken)
+ {
+ PhysicalAddress address = adapter.GetPhysicalAddress();
+ byte[] bytes = address.GetAddressBytes();
+
+ for (int i = 0; i < bytes.Length; i++)
+ {
+ MACIp += bytes[i].ToString("X2");
+
+ if (i != bytes.Length - 1)
+ {
+ MACIp += "-";
+ }
+ }
+ }
+ }
+
+ return MACIp;
+ }
+
+ ///
+ /// ȡԼ
+ ///
+ ///
+ public static string GetHostName()
+ {
+ //ؼϢ
+ IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
+
+ //ȡ
+ var hostName = computerProperties.HostName;
+
+ return !string.IsNullOrEmpty(hostName) ? hostName : "CoreShop.Professional";
+
+ }
+
+
+
+
+ ///
+ /// תMD5
+ ///
+ ///
+ ///
+ public static string GetMachineRandomKey(string str)
+ {
+ MD5 md5 = MD5.Create();
+ // ַתֽ
+ byte[] byteOld = Encoding.UTF8.GetBytes(str);
+ // üܷ
+ byte[] byteNew = md5.ComputeHash(byteOld);
+ // ܽתΪַ
+ StringBuilder sb = new StringBuilder();
+ foreach (byte b in byteNew)
+ {
+ // ֽת16Ʊʾַ
+ sb.Append(b.ToString("x2"));
+ }
+ // ؼַܵ
+ return sb.ToString();
+ }
+
+
}
}
\ No newline at end of file
diff --git a/CoreCms.Net.Web.Admin/appsettings.json b/CoreCms.Net.Web.Admin/appsettings.json
index decb7232..7748f2de 100644
--- a/CoreCms.Net.Web.Admin/appsettings.json
+++ b/CoreCms.Net.Web.Admin/appsettings.json
@@ -29,9 +29,9 @@
},
//jwt授权认证的一些设置
"JwtConfig": {
- "SecretKey": "8kh2luzmp0oq9wfbdeasygj647vr531n",
- "Issuer": "CoreShopProfessional",
- "Audience": "CoreCms"
+ "SecretKey": "", //请自主填写一段英文数字等作为token令牌,16位+
+ "Issuer": "", //颁发者身份标识,如CoreShop.Professional
+ "Audience": "coreshop" //期望的接收人,如core,cms等
},
//跨域设置
"Cors": {
diff --git a/CoreCms.Net.Web.WebApi/appsettings.json b/CoreCms.Net.Web.WebApi/appsettings.json
index 034a611b..067f5716 100644
--- a/CoreCms.Net.Web.WebApi/appsettings.json
+++ b/CoreCms.Net.Web.WebApi/appsettings.json
@@ -29,9 +29,9 @@
},
//jwt授权认证的一些设置
"JwtConfig": {
- "SecretKey": "8kh2luzmp0oq9wfbdeasygj647vr531n",
- "Issuer": "CoreShopProfessional",
- "Audience": "CoreCms"
+ "SecretKey": "", //请自主填写一段英文数字等作为token令牌,16位+
+ "Issuer": "", //颁发者身份标识,如CoreShop.Professional
+ "Audience": "coreshop" //期望的接收人,如core,cms等
},
//跨域设置
"Cors": {