Commit 949fdfe0 by 何阳

NEW: 1. 增加登陆账号加密

parent f21ed7f6
......@@ -11,8 +11,10 @@ namespace FaceServer
{
static Configuration settings;
public static Section Api;
private static string _filename;
public static void Load(string filename)
{
_filename= filename;
settings = Configuration.LoadFromFile(filename);
Api = settings["api"];
User = Api["User"].GetValueOrDefault("15995200590");
......@@ -20,6 +22,8 @@ namespace FaceServer
BaseUrl = Api["BaseUrl"].GetValueOrDefault("https://saas-uat.guke.tech");
LoginUrl = Api["LoginUrl"].GetValueOrDefault("/api/ucpm/console/token");
Test = Api["Test"].GetValueOrDefault(100);
Roi = Api["Roi"].GetValueOrDefault(420);
ENCRYPT_PASSWD = Api["ENCRYPT_PASSWD"].GetValueOrDefault(false);
}
public static string User { get; set; }
......@@ -29,5 +33,14 @@ namespace FaceServer
public static int Test { get; set; }
public static string OMP_TOKEN { get; internal set; }
public static string TENANT_ID { get; internal set; }
public static int Roi { get; internal set; }
public static bool ENCRYPT_PASSWD { get; internal set; }
public static void Set(string section, string key, string value)
{
var sec = settings[section];
sec[key].SetValue(value);
settings.SaveToFile(_filename);
}
}
}
......@@ -175,6 +175,7 @@
<Compile Include="DTO\OssFile.cs" />
<Compile Include="DTO\UserInfo.cs" />
<Compile Include="DTO\UserLoginVo.cs" />
<Compile Include="Server\EncryptionHelper.cs" />
<Compile Include="Server\FaceDataSet.cs" />
<Compile Include="Util\ConvertEx.cs" />
<Compile Include="Util\FaceRecognitionThread.cs" />
......
......@@ -32,6 +32,7 @@
this.cbPowerOn = new System.Windows.Forms.CheckBox();
this.tbROI = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.btSet = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// tbLog
......@@ -70,11 +71,22 @@
this.label1.TabIndex = 3;
this.label1.Text = "ROI大小";
//
// btSet
//
this.btSet.Location = new System.Drawing.Point(88, 472);
this.btSet.Name = "btSet";
this.btSet.Size = new System.Drawing.Size(56, 23);
this.btSet.TabIndex = 4;
this.btSet.Text = "设置";
this.btSet.UseVisualStyleBackColor = true;
this.btSet.Click += new System.EventHandler(this.btSet_Click);
//
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1238, 499);
this.Controls.Add(this.btSet);
this.Controls.Add(this.label1);
this.Controls.Add(this.tbROI);
this.Controls.Add(this.cbPowerOn);
......@@ -95,6 +107,7 @@
private System.Windows.Forms.CheckBox cbPowerOn;
private System.Windows.Forms.TextBox tbROI;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btSet;
}
}
......@@ -26,6 +26,7 @@ namespace FaceServer
trayIcon.MouseDoubleClick += TrayIcon_MouseDoubleClick;
this.ShowInTaskbar = false;//任务栏中显示标志
Config.Load("config.ini");
tbROI.Text = Config.Roi.ToString();
}
private void TrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
......@@ -105,7 +106,7 @@ namespace FaceServer
{
Log.Information("重新初始化人脸服务");
Server = new FaceRecognitionServer("Face", "Model");
Server.RoiSize = 480;
Server.RoiSize = Convert.ToInt32(tbROI.Text);
Log.Information("人脸服务初始化成功");
});
......@@ -219,7 +220,7 @@ namespace FaceServer
{
Log.Information("开始初始化人脸服务");
Server = new FaceRecognitionServer("Face", "Model");
Server.RoiSize = 480;
Server.RoiSize = Convert.ToInt32(tbROI.Text);
Log.Information("人脸服务初始化成功");
_initCompletionSource.SetResult(true);
});
......@@ -325,5 +326,15 @@ namespace FaceServer
this.Hide();
}
}
private void btSet_Click(object sender, EventArgs e)
{
Config.Set("Api", "Roi", tbROI.Text);
if (Server != null)
{
Server.RoiSize = Convert.ToInt32(tbROI.Text);
}
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace FaceServer.Server
{
public class EncryptionHelper
{
private static byte[] aes_key = new byte[16]
{
18, 52, 86, 120, 144, 171, 205, 239, 18, 52,
86, 120, 144, 171, 205, 239
};
public static string GetMD5String(string str)
{
MD5 mD = MD5.Create();
byte[] bytes = Encoding.UTF8.GetBytes(str);
byte[] data = mD.ComputeHash(bytes);
return GetbyteToString(data);
}
public static string GetMD5String(string str, HashAlgorithm hash)
{
byte[] bytes = Encoding.UTF8.GetBytes(str);
byte[] data = hash.ComputeHash(bytes);
return GetbyteToString(data);
}
public static string GetMD5FromFile(string path)
{
MD5 mD = MD5.Create();
if (!File.Exists(path))
{
return "";
}
FileStream inputStream = File.OpenRead(path);
byte[] data = mD.ComputeHash(inputStream);
return GetbyteToString(data);
}
private static string GetbyteToString(byte[] data)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
stringBuilder.Append(data[i].ToString("x2"));
}
return stringBuilder.ToString();
}
public static byte[] AESEncrypt(string plainText, string strKey)
{
SymmetricAlgorithm symmetricAlgorithm = Rijndael.Create();
byte[] bytes = Encoding.UTF8.GetBytes(plainText);
symmetricAlgorithm.Key = Encoding.UTF8.GetBytes(strKey);
symmetricAlgorithm.IV = aes_key;
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, symmetricAlgorithm.CreateEncryptor(), CryptoStreamMode.Write);
cryptoStream.Write(bytes, 0, bytes.Length);
cryptoStream.FlushFinalBlock();
byte[] result = memoryStream.ToArray();
cryptoStream.Close();
memoryStream.Close();
return result;
}
public static byte[] AESDecrypt(byte[] cipherText, string strKey)
{
SymmetricAlgorithm symmetricAlgorithm = Rijndael.Create();
symmetricAlgorithm.Key = Encoding.UTF8.GetBytes(strKey);
symmetricAlgorithm.IV = aes_key;
byte[] array = new byte[cipherText.Length];
MemoryStream memoryStream = new MemoryStream(cipherText);
CryptoStream cryptoStream = new CryptoStream(memoryStream, symmetricAlgorithm.CreateDecryptor(), CryptoStreamMode.Read);
cryptoStream.Read(array, 0, array.Length);
cryptoStream.Close();
memoryStream.Close();
return array;
}
public static string AESEncrypt(string toEncrypt, string key, string iv)
{
if (string.IsNullOrWhiteSpace(toEncrypt))
{
return toEncrypt;
}
using RijndaelManaged rijndaelManaged = new RijndaelManaged();
rijndaelManaged.Mode = CipherMode.CBC;
rijndaelManaged.Padding = PaddingMode.Zeros;
rijndaelManaged.FeedbackSize = 128;
rijndaelManaged.Key = Encoding.UTF8.GetBytes(key);
rijndaelManaged.IV = Encoding.UTF8.GetBytes(iv);
ICryptoTransform transform = rijndaelManaged.CreateEncryptor(rijndaelManaged.Key, rijndaelManaged.IV);
using MemoryStream memoryStream = new MemoryStream();
using CryptoStream stream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Write);
using (StreamWriter streamWriter = new StreamWriter(stream))
{
streamWriter.Write(toEncrypt);
}
byte[] inArray = memoryStream.ToArray();
return Convert.ToBase64String(inArray);
}
public static string AESDecrypt(string toDecrypt, string key, string iv)
{
if (string.IsNullOrWhiteSpace(toDecrypt))
{
return toDecrypt;
}
byte[] buffer = Convert.FromBase64String(toDecrypt);
using RijndaelManaged rijndaelManaged = new RijndaelManaged();
rijndaelManaged.Mode = CipherMode.CBC;
rijndaelManaged.Padding = PaddingMode.Zeros;
rijndaelManaged.FeedbackSize = 128;
rijndaelManaged.Key = Encoding.UTF8.GetBytes(key);
rijndaelManaged.IV = Encoding.UTF8.GetBytes(iv);
ICryptoTransform transform = rijndaelManaged.CreateDecryptor(rijndaelManaged.Key, rijndaelManaged.IV);
using MemoryStream stream = new MemoryStream(buffer);
using CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Read);
using StreamReader streamReader = new StreamReader(stream2);
return streamReader.ReadToEnd().TrimEnd(default(char));
}
}
}
......@@ -147,7 +147,19 @@ namespace FaceServer.Server
UserLoginVo user = new UserLoginVo();
user.grantType = "password";
user.username = Config.User;
user.password = Config.Passwd;
if (Config.ENCRYPT_PASSWD)
{
Log.Information("进入密码加密模式");
// MD5加密并转小写
var hash = EncryptionHelper.GetMD5String(user.password).ToLower();
Log.Information($"加密后={hash}");
user.password = hash;
}
else
{
user.password = Config.Passwd;
}
Log.Information($"登陆管理账号:{user.username}");
......
......@@ -3,4 +3,6 @@ User=15995200590
Passwd=123456
BaseUrl=https://saas-test.guke.tech/
LoginUrl=api/ucpm/console/token
Test=100
\ No newline at end of file
Roi=560
Test=100
ENCRYPT_PASSWD=True
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment