...
This commit is contained in:
@@ -42,7 +42,7 @@ namespace Back.Controllers
|
|||||||
{
|
{
|
||||||
var resultValidationmodel = await _mobilevalidation.ValidateAsync(model.Mobile);
|
var resultValidationmodel = await _mobilevalidation.ValidateAsync(model.Mobile);
|
||||||
if (!resultValidationmodel.IsValid)
|
if (!resultValidationmodel.IsValid)
|
||||||
return BadRequest(resultValidationmodel.Errors);
|
return BadRequest(resultValidationmodel.Errors.Select(s=>s.ErrorMessage ).ToList());
|
||||||
return Ok(await _sBase.CreateCsrAndPrivateKey(model));
|
return Ok(await _sBase.CreateCsrAndPrivateKey(model));
|
||||||
}
|
}
|
||||||
[HttpPost("ReadPublicKeyFromCER")]
|
[HttpPost("ReadPublicKeyFromCER")]
|
||||||
|
@@ -99,14 +99,12 @@ namespace Back.Services
|
|||||||
string csr = Encoding.UTF8.GetString(buffer);
|
string csr = Encoding.UTF8.GetString(buffer);
|
||||||
stream.Flush();
|
stream.Flush();
|
||||||
stream.Close();
|
stream.Close();
|
||||||
taxTools.csr = csr;
|
|
||||||
taxTools.Base64csr = Convert.ToBase64String(buffer);
|
taxTools.Base64csr = Convert.ToBase64String(buffer);
|
||||||
taxTools.typecsr = "Csr";
|
taxTools.typecsr = "Csr";
|
||||||
stream = File.Open($"C:\\OpenSSL\\bin\\{model.cn}.key", FileMode.Open);
|
stream = File.Open($"C:\\OpenSSL\\bin\\{model.cn}.key", FileMode.Open);
|
||||||
buffer = new byte[stream.Length];
|
buffer = new byte[stream.Length];
|
||||||
stream.Read(buffer, 0, (int)stream.Length);
|
stream.Read(buffer, 0, (int)stream.Length);
|
||||||
string key = Encoding.UTF8.GetString(buffer);
|
string key = Encoding.UTF8.GetString(buffer);
|
||||||
taxTools.key = key;
|
|
||||||
taxTools.Base64key = Convert.ToBase64String(buffer);
|
taxTools.Base64key = Convert.ToBase64String(buffer);
|
||||||
taxTools.typekey = "key";
|
taxTools.typekey = "key";
|
||||||
stream.Flush();
|
stream.Flush();
|
||||||
@@ -193,7 +191,6 @@ namespace Back.Services
|
|||||||
//});
|
//});
|
||||||
return new PublicKeyDTO
|
return new PublicKeyDTO
|
||||||
{
|
{
|
||||||
PublicKey = PublicKey,
|
|
||||||
PublicKeyBase64 = Convert.ToBase64String(buffer),
|
PublicKeyBase64 = Convert.ToBase64String(buffer),
|
||||||
type = "txt"
|
type = "txt"
|
||||||
};
|
};
|
||||||
|
@@ -8,6 +8,7 @@ namespace Back.Validations
|
|||||||
{
|
{
|
||||||
public MobileValidation()
|
public MobileValidation()
|
||||||
{
|
{
|
||||||
|
CascadeMode = CascadeMode.Stop;
|
||||||
RuleFor(m => m)
|
RuleFor(m => m)
|
||||||
.NotEmpty().WithMessage("موبایل نمی تواند باشد")
|
.NotEmpty().WithMessage("موبایل نمی تواند باشد")
|
||||||
.NotNull().WithMessage("موبایل نمی تواند باشد")
|
.NotNull().WithMessage("موبایل نمی تواند باشد")
|
||||||
|
@@ -4,13 +4,15 @@ namespace Shared.DTOs
|
|||||||
{
|
{
|
||||||
public class CsrPrivateKeyDto
|
public class CsrPrivateKeyDto
|
||||||
{
|
{
|
||||||
[Required]
|
|
||||||
|
[Required(ErrorMessage = "cn نمیتواند خالی باشد")]
|
||||||
public string cn { get; set; }
|
public string cn { get; set; }
|
||||||
[Required]
|
[Required(ErrorMessage = "sn نمیتواند خالی باشد")]
|
||||||
public string sn { get; set; }
|
public string sn { get; set; }
|
||||||
[Required]
|
[Required(ErrorMessage = "company نمیتواند خالی باشد")]
|
||||||
public string company { get; set; }
|
public string company { get; set; }
|
||||||
[Required]
|
[Required(ErrorMessage = "mobile نمیتواند خالی باشد")]
|
||||||
|
[Length(11,11,ErrorMessage ="mobile باید 11 کاراکتر باشد")]
|
||||||
public string Mobile { get; set; }
|
public string Mobile { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
{
|
{
|
||||||
public class PublicKeyDTO
|
public class PublicKeyDTO
|
||||||
{
|
{
|
||||||
public string PublicKey { get; set; }
|
|
||||||
public string PublicKeyBase64 { get; set; }
|
public string PublicKeyBase64 { get; set; }
|
||||||
public string type { get; set; }
|
public string type { get; set; }
|
||||||
}
|
}
|
||||||
|
@@ -2,10 +2,8 @@
|
|||||||
{
|
{
|
||||||
public class TaxToolsDTO
|
public class TaxToolsDTO
|
||||||
{
|
{
|
||||||
public string csr { get; set; }
|
|
||||||
public string Base64csr { get; set; }
|
public string Base64csr { get; set; }
|
||||||
public string typecsr { get; set; }
|
public string typecsr { get; set; }
|
||||||
public string key { get; set; }
|
|
||||||
public string Base64key { get; set; }
|
public string Base64key { get; set; }
|
||||||
public string typekey { get; set; }
|
public string typekey { get; set; }
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,7 @@
|
|||||||
@using Shared.DTOs
|
@using Shared.DTOs
|
||||||
|
@using System.Text
|
||||||
|
@inject HttpClient _hc
|
||||||
|
@inject IJSRuntime JS
|
||||||
<div class="contact-info-area pb-90" id="contact">
|
<div class="contact-info-area pb-90" id="contact">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -9,73 +12,196 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row gx-0">
|
<div class="row gx-0">
|
||||||
<h5 class="inner-section-subtitle">ابزار/سامانه مودیان</h5>
|
<h5 class="inner-section-subtitle">ابزار/سامانه مودیان</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="popular-blog-title mb-40">
|
<div class="popular-blog-title mb-40">
|
||||||
<h4>ساخت فایل CSR</h4>
|
<h4>1)ساخت فایل CSR</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row gx-0">
|
<div class="row gx-0">
|
||||||
<div class="contact-form-right-warp">
|
<div class="contact-form-right-warp">
|
||||||
<div class="postbox__comment-form">
|
<div class="postbox__comment-form">
|
||||||
|
<EditForm EditContext="editContext" OnValidSubmit="CreateCsrAndPrivateKey">
|
||||||
<div class="row gx-20">
|
<DataAnnotationsValidator />
|
||||||
<div class="col-12">
|
<div class="postbox__comment-input mb-35">
|
||||||
<div class="postbox__comment-input mb-30">
|
<ValidationMessage For="()=>modelTaxTools.cn" />
|
||||||
<input @bind="model.cn" type="text" class="inputText" required="">
|
<ValidationMessage For="()=>modelTaxTools.sn" />
|
||||||
|
<ValidationMessage For="()=>modelTaxTools.company" />
|
||||||
|
<ValidationMessage For="()=>modelTaxTools.Mobile" />
|
||||||
|
</div>
|
||||||
|
<div class="row gx-20">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="postbox__comment-input mb-30">
|
||||||
|
<InputText @bind-Value="modelTaxTools.cn" id="cn" type="text" class="inputText" required="" />
|
||||||
<span class="floating-label">cn</span>
|
<span class="floating-label">cn</span>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12">
|
</div>
|
||||||
<div class="postbox__comment-input mb-30">
|
<div class="col-12">
|
||||||
<input @bind="model.sn" type="text" class="inputText" required="">
|
<div class="postbox__comment-input mb-30">
|
||||||
<span class="floating-label">sn</span>
|
<InputText @bind-Value="modelTaxTools.sn" id="sn" type="text" class="inputText" required="" />
|
||||||
</div>
|
<span class="floating-label">sn</span>
|
||||||
</div>
|
|
||||||
<div class="col-12">
|
|
||||||
<div class="postbox__comment-input mb-35">
|
|
||||||
<input @bind="model.company" type="text" class="inputText" required="">
|
|
||||||
<span class="floating-label">Company</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="postbox__comment-input mb-35">
|
<div class="postbox__comment-input mb-35">
|
||||||
<input @bind="model.Mobile" type="text" class="inputText" required="">
|
<InputText @bind-Value="modelTaxTools.company" id="company" type="text" class="inputText" required="" />
|
||||||
|
<span class="floating-label">Company</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="postbox__comment-input mb-35">
|
||||||
|
<InputText @bind-Value="modelTaxTools.Mobile" id="Mobile" type="text" class="inputText" required="" />
|
||||||
<span class="floating-label">Mobile</span>
|
<span class="floating-label">Mobile</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xxl-6">
|
|
||||||
<div class="postbox__btn-box w-50">
|
|
||||||
<button onclick="@CreateCsrAndPrivateKey" class="btn btn-outline-primary">ایجاد CSR و PrivateKey</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="col-xxl-6">
|
<div class="col-xxl-6">
|
||||||
|
|
||||||
|
<div class="postbox__btn-box w-50">
|
||||||
|
<button type="submit" class="btn btn-outline-primary">ایجاد CSR و PrivateKey</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
@* <div class="col-xxl-6">
|
||||||
<div class="postbox__btn-box">
|
<div class="postbox__btn-box">
|
||||||
<button onclick="@ReadPublicKeyFromCER" class="btn btn-outline-primary">خواندن PublicKey</button>
|
<a onclick="@ReadPublicKeyFromCER" class="btn btn-outline-primary">2)خواندن PublicKey</a>
|
||||||
</div>
|
</div>
|
||||||
|
</div> *@
|
||||||
</div>
|
</div>
|
||||||
|
</EditForm>
|
||||||
|
<br /> <br />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="popular-blog-title mb-20">
|
||||||
|
<h4>2)خواندن کلید عمومی</h4>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
حداکثر سایز مجاز فایل @maxFileSize بایت:
|
||||||
|
<InputFile OnChange="ReadPublicKeyFromCER" multiple />
|
||||||
|
</label>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private CsrPrivateKeyDto? model { get; set; } = new CsrPrivateKeyDto();
|
private long maxFileSize = 1024 * 15;
|
||||||
}
|
|
||||||
@functions{
|
|
||||||
private void CreateCsrAndPrivateKey()
|
private EditContext? editContext;
|
||||||
|
[SupplyParameterFromForm]
|
||||||
|
private CsrPrivateKeyDto? modelTaxTools { get; set; } = new CsrPrivateKeyDto();
|
||||||
|
|
||||||
|
private ValidationMessageStore? messageStore;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
|
// modelTaxTools ??= new();
|
||||||
|
// editContext = new(modelTaxTools);
|
||||||
|
// editContext.OnValidationRequested += HandleValidationRequested;
|
||||||
|
// messageStore = new(editContext);
|
||||||
|
|
||||||
|
editContext = new EditContext(modelTaxTools);
|
||||||
|
messageStore = new(editContext);
|
||||||
}
|
}
|
||||||
private void ReadPublicKeyFromCER()
|
|
||||||
|
// private void HandleValidationRequested(object? sender,
|
||||||
|
// ValidationRequestedEventArgs args)
|
||||||
|
// {
|
||||||
|
// messageStore?.Clear();
|
||||||
|
|
||||||
|
|
||||||
|
// // messageStore?.Add(() => modelTaxTools.Mobile, "Select at least one.");
|
||||||
|
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
@functions {
|
||||||
|
private async Task CreateCsrAndPrivateKey()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var request = await _hc.PostAsJsonAsync("Base/CreateCsrAndPrivateKey", modelTaxTools);
|
||||||
|
if (request.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
var res = await request.Content.ReadFromJsonAsync<TaxToolsDTO>();
|
||||||
|
await DownloadFileFromStream(res.Base64csr, $"{modelTaxTools.cn}.{res.typecsr}");
|
||||||
|
await DownloadFileFromStream(res.Base64key, $"{modelTaxTools.cn}.{res.typekey}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var error = await request.Content.ReadFromJsonAsync<List<string>>();
|
||||||
|
messageStore?.Add(() => modelTaxTools.Mobile, error);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
private async Task ReadPublicKeyFromCER(InputFileChangeEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.GetMultipleFiles()[0].Size <= maxFileSize)
|
||||||
|
{
|
||||||
|
string Base64Str = "";
|
||||||
|
using (MemoryStream stream = new MemoryStream())
|
||||||
|
{
|
||||||
|
await e.GetMultipleFiles()[0].OpenReadStream(maxFileSize).CopyToAsync(stream);
|
||||||
|
|
||||||
|
byte[] Array = stream.ToArray();
|
||||||
|
Base64Str = Convert.ToBase64String(Array);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (!string.IsNullOrEmpty(Base64Str))
|
||||||
|
// {
|
||||||
|
// var request = await _hc.PostAsJsonAsync("Base/ReadPublicKeyFromCER", Base64Str);
|
||||||
|
// if (request.IsSuccessStatusCode)
|
||||||
|
// {
|
||||||
|
// var res = await request.Content.ReadFromJsonAsync<PublicKeyDTO>();
|
||||||
|
// await DownloadFileFromStream(res.PublicKeyBase64, $"{modelTaxTools.cn}.{res.type}");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
private Stream GetFileStream(byte[] bytes)
|
||||||
|
{
|
||||||
|
var fileStream = new MemoryStream(bytes);
|
||||||
|
|
||||||
|
return fileStream;
|
||||||
|
}
|
||||||
|
private async Task DownloadFileFromStream(string Base64, string FileName)
|
||||||
|
{
|
||||||
|
byte[] bytes = System.Convert.FromBase64String(Base64);
|
||||||
|
|
||||||
|
var fileStream = GetFileStream(bytes);
|
||||||
|
// var fileName = "log.bin";
|
||||||
|
|
||||||
|
using var streamRef = new DotNetStreamReference(stream: fileStream);
|
||||||
|
|
||||||
|
await JS.InvokeVoidAsync("downloadFileFromStream", FileName, streamRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<script>
|
||||||
|
window.downloadFileFromStream = async (fileName, contentStreamReference) => {
|
||||||
|
const arrayBuffer = await contentStreamReference.arrayBuffer();
|
||||||
|
const blob = new Blob([arrayBuffer]);
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const anchorElement = document.createElement('a');
|
||||||
|
anchorElement.href = url;
|
||||||
|
anchorElement.download = fileName ?? '';
|
||||||
|
anchorElement.click();
|
||||||
|
anchorElement.remove();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
</script>
|
Reference in New Issue
Block a user