添加登录注册业务
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
@@ -7,63 +8,68 @@ namespace Yi.Framework.Common.Helper
|
||||
public class MD5Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 16位MD5加密
|
||||
/// 生成PasswordSalt
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt16(string password)
|
||||
/// <returns>返回string</returns>
|
||||
public static string GenerateSalt()
|
||||
{
|
||||
byte[] buf = new byte[16];
|
||||
#pragma warning disable SYSLIB0023 // 类型或成员已过时
|
||||
(new RNGCryptoServiceProvider()).GetBytes(buf);
|
||||
#pragma warning restore SYSLIB0023 // 类型或成员已过时
|
||||
return Convert.ToBase64String(buf);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加密密码
|
||||
/// </summary>
|
||||
/// <param name="pass">密码</param>
|
||||
/// <param name="passwordFormat">加密类型</param>
|
||||
/// <param name="salt">PasswordSalt</param>
|
||||
/// <returns>加密后的密码</returns>
|
||||
public static string SHA2Encode(string pass, string salt, int passwordFormat = 1)
|
||||
{
|
||||
if (passwordFormat == 0) // MembershipPasswordFormat.Clear
|
||||
return pass;
|
||||
|
||||
byte[] bIn = Encoding.Unicode.GetBytes(pass);
|
||||
byte[] bSalt = Convert.FromBase64String(salt);
|
||||
byte[] bAll = new byte[bSalt.Length + bIn.Length];
|
||||
byte[] bRet = null;
|
||||
|
||||
Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);
|
||||
Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);
|
||||
|
||||
#pragma warning disable SYSLIB0021 // 类型或成员已过时
|
||||
var md5 = new MD5CryptoServiceProvider();
|
||||
var s = SHA512Managed.Create();
|
||||
#pragma warning restore SYSLIB0021 // 类型或成员已过时
|
||||
string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(password)), 4, 8);
|
||||
t2 = t2.Replace("-", string.Empty);
|
||||
return t2;
|
||||
}
|
||||
bRet = s.ComputeHash(bAll);
|
||||
|
||||
/// <summary>
|
||||
/// 32位MD5加密
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt32(string password = "")
|
||||
return ConvertEx.ToUrlBase64String(bRet);
|
||||
}
|
||||
}
|
||||
public class ConvertEx
|
||||
{
|
||||
static readonly char[] padding = { '=' };
|
||||
public static string ToUrlBase64String(byte[] inArray)
|
||||
{
|
||||
string pwd = string.Empty;
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(password) && !string.IsNullOrWhiteSpace(password))
|
||||
{
|
||||
MD5 md5 = MD5.Create(); //实例化一个md5对像
|
||||
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
||||
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
|
||||
// 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
|
||||
foreach (var item in s)
|
||||
{
|
||||
// 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
|
||||
pwd = string.Concat(pwd, item.ToString("X2"));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new Exception($"错误的 password 字符串:【{password}】");
|
||||
}
|
||||
return pwd;
|
||||
var str = Convert.ToBase64String(inArray);
|
||||
str = str.TrimEnd(padding).Replace('+', '-').Replace('/', '_');
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 64位MD5加密
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt64(string password)
|
||||
public static byte[] FromUrlBase64String(string s)
|
||||
{
|
||||
// 实例化一个md5对像
|
||||
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
||||
MD5 md5 = MD5.Create();
|
||||
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
|
||||
return Convert.ToBase64String(s);
|
||||
}
|
||||
string incoming = s.Replace('_', '/').Replace('-', '+');
|
||||
switch (s.Length % 4)
|
||||
{
|
||||
case 2: incoming += "=="; break;
|
||||
case 3: incoming += "="; break;
|
||||
}
|
||||
byte[] bytes = Convert.FromBase64String(incoming);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Common.Models
|
||||
{
|
||||
public class AxiosUrlsModel
|
||||
{
|
||||
public string get { get; set; }
|
||||
public string update { get; set; }
|
||||
public string del { get; set; }
|
||||
public string add { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user