feat: 客户端模式增加加密工具

This commit is contained in:
Argo Zhang 2020-03-01 12:41:05 +08:00
parent 0cf1d3cb60
commit d1770d5326
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
5 changed files with 142 additions and 3 deletions

View File

@ -0,0 +1,50 @@
using Longbow.Security.Cryptography;
using Microsoft.AspNetCore.Mvc;
namespace Bootstrap.Client.Controllers.Api
{
/// <summary>
/// 运维邮件发送接口
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class EncrptyController : ControllerBase
{
/// <summary>
/// 生成加密盐值方法
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Salt()
{
return new JsonResult(LgbCryptography.GenerateSalt());
}
/// <summary>
/// 根据提供的原始密码与盐值计算 Hash 值
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
[HttpPost]
public IActionResult Hash([FromBody]EncrptyPostData data)
{
return new JsonResult(LgbCryptography.ComputeHash(data.Password, data.Salt));
}
}
/// <summary>
/// 加密数据提交类
/// </summary>
public class EncrptyPostData
{
/// <summary>
/// 获得/设置 加密盐值
/// </summary>
public string Salt { get; set; } = "";
/// <summary>
/// 获得/设置 要加密的原始密码
/// </summary>
public string Password { get; set; } = "";
}
}

View File

@ -11,14 +11,13 @@ namespace Bootstrap.Client
/// <summary>
/// Tools 控制器
/// </summary>
[Authorize]
[Authorize(Roles = "Administrators")]
public class ToolsController : Controller
{
/// <summary>
/// SQL 视图
/// </summary>
/// <returns></returns>
[Authorize(Roles = "Administrators")]
[HttpGet]
public IActionResult SQL()
{
@ -29,7 +28,6 @@ namespace Bootstrap.Client
/// SQL 视图
/// </summary>
/// <returns></returns>
[Authorize(Roles = "Administrators")]
[HttpGet]
public IActionResult Mail()
{
@ -100,5 +98,15 @@ namespace Bootstrap.Client
return db.Execute(sql);
}
}
/// <summary>
/// 加密工具控制器
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Encrpty()
{
return View(new EncrptyModel(this));
}
}
}

View File

@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Mvc;
namespace Bootstrap.Client.Models
{
/// <summary>
/// Encrpty Model
/// </summary>
public class EncrptyModel : NavigatorBarModel
{
/// <summary>
/// 构造函数
/// </summary>
public EncrptyModel(ControllerBase controller) : base(controller)
{
}
}
}

View File

@ -0,0 +1,38 @@
@model EncrptyModel
@{
ViewData["Title"] = "加密工具类";
}
@section javascript {
<script src="~/js/encrpty.js"></script>
}
<div class="card">
<div class="card-header">加密工具</div>
<div class="card-body">
<div class="form-inline">
<div class="row">
<div class="form-group col-12">
<label class="control-label" for="password">原始密码:</label>
<input type="password" id="password" class="form-control flex-fill" autocomplete="off" />
</div>
<div class="form-group col-12">
<label class="control-label" for="salt">密码盐:</label>
<div class="input-group flex-fill">
<input type="text" id="salt" class="form-control" autocomplete="off" />
<div class="input-group-append">
<button type="button" data-method='salt' class="btn btn-secondary"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i><span>生成</span></button>
</div>
</div>
</div>
<div class="form-group col-12">
<label class="control-label" for="hash">Hash</label>
<div class="input-group flex-fill">
<input type="text" readonly id="hash" class="form-control" autocomplete="off" />
<div class="input-group-append">
<button type="button" data-method="hash" class="btn btn-secondary"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i><span>生成</span></button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,25 @@
$(function () {
$(document).on('click', '[data-method]', function (e) {
var method = $(this).attr('data-method');
switch (method) {
case 'salt':
$.bc({
url: 'api/Encrpty/Salt', method: 'get', callback: function (result) {
$('#salt').val(result);
}
});
break;
case 'hash':
$.bc({
url: 'api/Encrpty/Hash', method: 'post', data: { password: $('#password').val(), salt: $('#salt').val() }, callback: function (result) {
$('#hash').val(result);
}
});
break;
default:
break;
}
});
$.footer();
});