u
This commit is contained in:
@@ -2,12 +2,13 @@
|
|||||||
using FrontOffice.Main.Utilities;
|
using FrontOffice.Main.Utilities;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using MudBlazor;
|
using MudBlazor;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace FrontOffice.Main.Pages;
|
namespace FrontOffice.Main.Pages;
|
||||||
public partial class Index
|
public partial class Index
|
||||||
{
|
{
|
||||||
[Inject] private PackageContract.PackageContractClient PackageClient { get; set; } = default!;
|
[Inject] private PackageContract.PackageContractClient PackageClient { get; set; } = default!;
|
||||||
|
[Inject] private MobileNumberEncryptor Encryptor { get; set; }
|
||||||
private string? _email;
|
private string? _email;
|
||||||
private bool _isLoadingPackages;
|
private bool _isLoadingPackages;
|
||||||
private List<Pack> _packs = new();
|
private List<Pack> _packs = new();
|
||||||
@@ -15,6 +16,17 @@ public partial class Index
|
|||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
await LoadPackagesAsync();
|
await LoadPackagesAsync();
|
||||||
|
|
||||||
|
|
||||||
|
//string mobileNumber = "09387342688";
|
||||||
|
|
||||||
|
//// انکریپت کردن
|
||||||
|
//string encrypted = Encryptor.EncryptMobileNumber(mobileNumber);
|
||||||
|
//Console.WriteLine($"Encrypted: {encrypted}");
|
||||||
|
|
||||||
|
//// دیکریپت کردن برای تست
|
||||||
|
//string decrypted = Encryptor.DecryptMobileNumber(encrypted);
|
||||||
|
//Console.WriteLine($"Decrypted: {decrypted}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task LoadPackagesAsync()
|
private async Task LoadPackagesAsync()
|
||||||
|
|||||||
@@ -1,41 +1,62 @@
|
|||||||
<div class="org-chart-container">
|
@if (_currentUser != null)
|
||||||
<div class="org-tree">
|
{
|
||||||
<div class="org-node root-node" id="root-node">
|
<div class="org-chart-container">
|
||||||
<div class="node-card">
|
<div class="org-tree">
|
||||||
<div class="node-avatar">
|
<div class="org-node root-node" id="root-node">
|
||||||
<MudAvatar Size="Size.Large">
|
<div class="node-card">
|
||||||
<MudImage ObjectFit="ObjectFit.Cover"
|
<div class="node-avatar">
|
||||||
ObjectPosition="ObjectPosition.Center"
|
@if (!string.IsNullOrWhiteSpace(_currentUser.Avatar))
|
||||||
Src="images/avatar1.jpg" />
|
{
|
||||||
</MudAvatar>
|
<MudAvatar Size="Size.Large">
|
||||||
@if (_currentUser?.Children?.Any() == true)
|
<MudImage ObjectFit="ObjectFit.Cover"
|
||||||
{
|
ObjectPosition="ObjectPosition.Center"
|
||||||
<button class="expand-btn" @onclick="ToggleExpand" data-user-id="@_currentUser.Id">
|
Src="@_currentUser.Avatar" />
|
||||||
<MudIcon Icon="@(_isExpanded ? Icons.Material.Filled.Remove : Icons.Material.Filled.Add)" Size="Size.Small" />
|
</MudAvatar>
|
||||||
</button>
|
}
|
||||||
}
|
else
|
||||||
</div>
|
{
|
||||||
<div class="node-info">
|
<MudAvatar Size="Size.Large" Color="Color.Primary" Variant="Variant.Outlined">
|
||||||
<div class="node-name">@(_currentUser?.FirstName) @(_currentUser?.LastName)</div>
|
@(string.IsNullOrWhiteSpace(_currentUser.FirstName) ? "N" : _currentUser.FirstName.Substring(0, 1))
|
||||||
<div class="node-amounts">
|
</MudAvatar>
|
||||||
<div class="personal-amount">
|
}
|
||||||
<span class="label">خرید شخصی:</span>
|
|
||||||
<span class="amount">@(_currentUser?.PersonalPurchase?.ToThousands().ToCurrencyUnitIRT() ?? "0 تومان")</span>
|
@if (_currentUser?.Children?.Any() == true)
|
||||||
</div>
|
{
|
||||||
<div class="team-amount">
|
<button class="expand-btn" @onclick="ToggleExpand" data-user-id="@_currentUser.Id">
|
||||||
<span class="label">خرید تیمی:</span>
|
<MudIcon Icon="@(_isExpanded ? Icons.Material.Filled.Remove : Icons.Material.Filled.Add)" Size="Size.Small" />
|
||||||
<span class="amount">@(_currentUser?.TeamPurchase?.ToThousands().ToCurrencyUnitIRT() ?? "0 تومان")</span>
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div class="node-info">
|
||||||
|
@if (!string.IsNullOrWhiteSpace(_currentUser.FirstName) || !string.IsNullOrWhiteSpace(_currentUser.LastName))
|
||||||
|
{
|
||||||
|
<div class="node-name">@_currentUser.FirstName @_currentUser.LastName</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="node-name">@_currentUser.Mobile</div>
|
||||||
|
}
|
||||||
|
<div class="node-amounts">
|
||||||
|
<div class="personal-amount">
|
||||||
|
<span class="label">خرید شخصی:</span>
|
||||||
|
<span class="amount">@(_currentUser?.PersonalPurchase?.ToThousands().ToCurrencyUnitIRT() ?? "0 تومان")</span>
|
||||||
|
</div>
|
||||||
|
<div class="team-amount">
|
||||||
|
<span class="label">خرید تیمی:</span>
|
||||||
|
<span class="amount">@(_currentUser?.TeamPurchase?.ToThousands().ToCurrencyUnitIRT() ?? "0 تومان")</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
@if (_isExpanded && _currentUser?.Children?.Any() == true)
|
@if (_isExpanded && _currentUser?.Children?.Any() == true)
|
||||||
{
|
{
|
||||||
<CascadingValue Value="this">
|
<CascadingValue Value="this">
|
||||||
<OrganizationChartLevel Nodes="_currentUser.Children" Level="1" />
|
<OrganizationChartLevel Nodes="_currentUser.Children" Level="1" />
|
||||||
</CascadingValue>
|
</CascadingValue>
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
using static FrontOffice.Main.Pages.Profile.Components.OrganizationChartLevel;
|
using FrontOffice.BFF.User.Protobuf.Protos.User;
|
||||||
|
using Mapster;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using static FrontOffice.Main.Pages.Profile.Components.OrganizationChartLevel;
|
||||||
|
|
||||||
namespace FrontOffice.Main.Pages.Profile.Components;
|
namespace FrontOffice.Main.Pages.Profile.Components;
|
||||||
public partial class OrganizationChart
|
public partial class OrganizationChart
|
||||||
@@ -6,112 +9,82 @@ public partial class OrganizationChart
|
|||||||
private UserNode? _currentUser;
|
private UserNode? _currentUser;
|
||||||
private bool _isExpanded;
|
private bool _isExpanded;
|
||||||
|
|
||||||
|
[Inject] private UserContract.UserContractClient UserContract { get; set; } = default!;
|
||||||
|
private GetUserResponse _userProfile = new();
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
await LoadCurrentUser();
|
await LoadCurrentUser();
|
||||||
}
|
}
|
||||||
|
private async Task LoadUserProfile()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_userProfile = await UserContract.GetUserAsync(request: new());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// Handle the case when user is not authenticated or API fails
|
||||||
|
_userProfile = new GetUserResponse();
|
||||||
|
}
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
private async Task LoadCurrentUser()
|
private async Task LoadCurrentUser()
|
||||||
{
|
{
|
||||||
|
await LoadUserProfile();
|
||||||
|
|
||||||
|
|
||||||
// Mock data - replace with actual API call
|
// Mock data - replace with actual API call
|
||||||
_currentUser = new UserNode
|
_currentUser = new UserNode
|
||||||
{
|
{
|
||||||
Id = 1,
|
Id = _userProfile.Id,
|
||||||
FirstName = "علی",
|
FirstName = _userProfile.FirstName,
|
||||||
LastName = "رضایی",
|
LastName = _userProfile.LastName,
|
||||||
Avatar = "images/avatar1.jpg",
|
Mobile = _userProfile.Mobile,
|
||||||
PersonalPurchase = 2500000,
|
Avatar = _userProfile.AvatarPath,
|
||||||
TeamPurchase = 15000000,
|
PersonalPurchase = 0,
|
||||||
Children = new List<UserNode>
|
TeamPurchase = 0,
|
||||||
{
|
Children = await GetUserChildren(userId: _userProfile.Id)
|
||||||
new UserNode
|
|
||||||
{
|
|
||||||
Id = 2,
|
|
||||||
FirstName = "مریم",
|
|
||||||
LastName = "احمدی",
|
|
||||||
Avatar = "images/avatar2.jpg",
|
|
||||||
PersonalPurchase = 1800000,
|
|
||||||
TeamPurchase = 8500000,
|
|
||||||
Children = new List<UserNode>
|
|
||||||
{
|
|
||||||
new UserNode
|
|
||||||
{
|
|
||||||
Id = 5,
|
|
||||||
FirstName = "سارا",
|
|
||||||
LastName = "کریمی",
|
|
||||||
PersonalPurchase = 1200000,
|
|
||||||
TeamPurchase = 3200000,
|
|
||||||
Children = new List<UserNode>
|
|
||||||
{
|
|
||||||
new UserNode
|
|
||||||
{
|
|
||||||
Id = 8,
|
|
||||||
FirstName = "نازنین",
|
|
||||||
LastName = "رضایی",
|
|
||||||
PersonalPurchase = 950000,
|
|
||||||
TeamPurchase = 2100000
|
|
||||||
},
|
|
||||||
new UserNode
|
|
||||||
{
|
|
||||||
Id = 8,
|
|
||||||
FirstName = "فرزاد",
|
|
||||||
LastName = "رضایی",
|
|
||||||
PersonalPurchase = 950000,
|
|
||||||
TeamPurchase = 2100000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new UserNode
|
|
||||||
{
|
|
||||||
Id = 6,
|
|
||||||
FirstName = "امیر",
|
|
||||||
LastName = "حسینی",
|
|
||||||
PersonalPurchase = 950000,
|
|
||||||
TeamPurchase = 1800000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new UserNode
|
|
||||||
{
|
|
||||||
Id = 3,
|
|
||||||
FirstName = "حسن",
|
|
||||||
LastName = "کریمی",
|
|
||||||
Avatar = "images/avatar3.jpg",
|
|
||||||
PersonalPurchase = 2200000,
|
|
||||||
TeamPurchase = 9200000,
|
|
||||||
Children = new List<UserNode>
|
|
||||||
{
|
|
||||||
new UserNode
|
|
||||||
{
|
|
||||||
Id = 7,
|
|
||||||
FirstName = "فاطمه",
|
|
||||||
LastName = "رضایی",
|
|
||||||
PersonalPurchase = 1350000,
|
|
||||||
TeamPurchase = 4100000
|
|
||||||
},
|
|
||||||
new UserNode
|
|
||||||
{
|
|
||||||
Id = 7,
|
|
||||||
FirstName = "آرش",
|
|
||||||
LastName = "رضایی",
|
|
||||||
PersonalPurchase = 1350000,
|
|
||||||
TeamPurchase = 4100000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new UserNode
|
|
||||||
{
|
|
||||||
Id = 4,
|
|
||||||
FirstName = "زهرا",
|
|
||||||
LastName = "محمدی",
|
|
||||||
Avatar = "images/avatar4.jpg",
|
|
||||||
PersonalPurchase = 1950000,
|
|
||||||
TeamPurchase = 7800000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<List<UserNode>?> GetUserChildren(long userId)
|
||||||
|
{
|
||||||
|
Console.WriteLine("OK0");
|
||||||
|
if (userId != 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("OK1");
|
||||||
|
var children = await UserContract.GetAllUserByFilterAsync(request: new()
|
||||||
|
{
|
||||||
|
Filter = new()
|
||||||
|
{
|
||||||
|
ParentId = userId,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (children?.Models?.Any() == true)
|
||||||
|
{
|
||||||
|
Console.WriteLine("OK2");
|
||||||
|
var result = new List<UserNode>();
|
||||||
|
foreach (var item in children.Models)
|
||||||
|
{
|
||||||
|
var node = new UserNode
|
||||||
|
{
|
||||||
|
Id = item.Id,
|
||||||
|
FirstName = item.FirstName,
|
||||||
|
LastName = item.LastName,
|
||||||
|
Mobile = item.Mobile,
|
||||||
|
Avatar = item.AvatarPath,
|
||||||
|
ReferralCode = item.ReferralCode,
|
||||||
|
PersonalPurchase = 0,
|
||||||
|
TeamPurchase = 0,
|
||||||
|
Children = await GetUserChildren(userId: item.Id)
|
||||||
|
};
|
||||||
|
result.Add(node);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
private void ToggleExpand()
|
private void ToggleExpand()
|
||||||
{
|
{
|
||||||
_isExpanded = !_isExpanded;
|
_isExpanded = !_isExpanded;
|
||||||
|
|||||||
@@ -6,11 +6,22 @@
|
|||||||
<div class="node-connector"></div>
|
<div class="node-connector"></div>
|
||||||
<div class="node-card">
|
<div class="node-card">
|
||||||
<div class="node-avatar">
|
<div class="node-avatar">
|
||||||
<MudAvatar Size="@GetAvatarSize(Level)">
|
@if (!string.IsNullOrWhiteSpace(node.Avatar))
|
||||||
<MudImage ObjectFit="ObjectFit.Cover"
|
{
|
||||||
ObjectPosition="ObjectPosition.Center"
|
<MudAvatar Size="@GetAvatarSize(Level)">
|
||||||
Src="@(string.IsNullOrEmpty(node.Avatar) ? "images/avatar1.jpg" : node.Avatar)" />
|
<MudImage ObjectFit="ObjectFit.Cover"
|
||||||
</MudAvatar>
|
ObjectPosition="ObjectPosition.Center"
|
||||||
|
Src="@node.Avatar" />
|
||||||
|
</MudAvatar>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudAvatar Size="@GetAvatarSize(Level)"
|
||||||
|
Color="Color.Primary"
|
||||||
|
Variant="Variant.Outlined">
|
||||||
|
@(string.IsNullOrWhiteSpace(node.FirstName) ? "N" : node.FirstName.Substring(0, 1))
|
||||||
|
</MudAvatar>
|
||||||
|
}
|
||||||
@if (node.Children?.Any() == true)
|
@if (node.Children?.Any() == true)
|
||||||
{
|
{
|
||||||
<button class="expand-btn" @onclick="() => ToggleNodeExpand(node.Id)" data-user-id="@node.Id">
|
<button class="expand-btn" @onclick="() => ToggleNodeExpand(node.Id)" data-user-id="@node.Id">
|
||||||
@@ -19,7 +30,14 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div class="node-info">
|
<div class="node-info">
|
||||||
<div class="node-name">@node.FirstName @node.LastName</div>
|
@if (!string.IsNullOrWhiteSpace(node.FirstName) || !string.IsNullOrWhiteSpace(node.LastName))
|
||||||
|
{
|
||||||
|
<div class="node-name">@node.FirstName @node.LastName</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="node-name">@node.Mobile</div>
|
||||||
|
}
|
||||||
<div class="node-amounts">
|
<div class="node-amounts">
|
||||||
<div class="personal-amount">
|
<div class="personal-amount">
|
||||||
<span class="label">خرید شخصی:</span>
|
<span class="label">خرید شخصی:</span>
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ public partial class OrganizationChartLevel
|
|||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
public string? FirstName { get; set; }
|
public string? FirstName { get; set; }
|
||||||
public string? LastName { get; set; }
|
public string? LastName { get; set; }
|
||||||
|
public string? Mobile { get; set; }
|
||||||
|
public string? ReferralCode { get; set; }
|
||||||
public string? Avatar { get; set; }
|
public string? Avatar { get; set; }
|
||||||
public long? PersonalPurchase { get; set; }
|
public long? PersonalPurchase { get; set; }
|
||||||
public long? TeamPurchase { get; set; }
|
public long? TeamPurchase { get; set; }
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ public partial class Index
|
|||||||
|
|
||||||
private async Task ShareReferralCode()
|
private async Task ShareReferralCode()
|
||||||
{
|
{
|
||||||
var shareText = $"کد دعوت من در فرصت: {_userProfile.ReferralCode}\nبرای عضویت از این لینک استفاده کنید: {Navigation.BaseUri}?ref={_userProfile.ReferralCode}";
|
var shareText = $"کد دعوت من در فرصت: {_userProfile.ReferralCode}\nبرای عضویت از این لینک استفاده کنید:";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ ValidatorOptions.Global.LanguageManager = new CustomFluentValidationLanguageMana
|
|||||||
var appSettings = builder.Configuration.Get<AppSettings>();
|
var appSettings = builder.Configuration.Get<AppSettings>();
|
||||||
UrlUtility.DownloadUrl = appSettings.DownloadUrl;
|
UrlUtility.DownloadUrl = appSettings.DownloadUrl;
|
||||||
|
|
||||||
|
builder.Services.Configure<EncryptionSettings>(builder.Configuration.GetSection("EncryptionSettings"));
|
||||||
|
builder.Services.AddSingleton<MobileNumberEncryptor>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
@@ -51,3 +54,8 @@ public class AppSettings
|
|||||||
{
|
{
|
||||||
public string DownloadUrl { get; set; }
|
public string DownloadUrl { get; set; }
|
||||||
}
|
}
|
||||||
|
public class EncryptionSettings
|
||||||
|
{
|
||||||
|
public string Key { get; set; }
|
||||||
|
public string IV { get; set; }
|
||||||
|
}
|
||||||
122
src/FrontOffice.Main/Utilities/MobileNumberEncryptor.cs
Normal file
122
src/FrontOffice.Main/Utilities/MobileNumberEncryptor.cs
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace FrontOffice.Main.Utilities;
|
||||||
|
|
||||||
|
public class MobileNumberEncryptor
|
||||||
|
{
|
||||||
|
private readonly string _key;
|
||||||
|
private readonly string _iv;
|
||||||
|
public MobileNumberEncryptor(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
var encryptionSettings = configuration.GetSection("EncryptionSettings").Get<EncryptionSettings>();
|
||||||
|
|
||||||
|
_key = encryptionSettings?.Key ?? throw new ArgumentNullException("Encryption Key not found in configuration");
|
||||||
|
_iv = encryptionSettings?.IV ?? throw new ArgumentNullException("Encryption IV not found in configuration");
|
||||||
|
|
||||||
|
// اعتبارسنجی سایز
|
||||||
|
ValidateKeyAndIV();
|
||||||
|
}
|
||||||
|
public MobileNumberEncryptor(string key, string iv)
|
||||||
|
{
|
||||||
|
_key = key;
|
||||||
|
_iv = iv;
|
||||||
|
ValidateKeyAndIV();
|
||||||
|
}
|
||||||
|
private void ValidateKeyAndIV()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] keyBytes = Convert.FromBase64String(_key);
|
||||||
|
byte[] ivBytes = Convert.FromBase64String(_iv);
|
||||||
|
|
||||||
|
if (keyBytes.Length != 32)
|
||||||
|
throw new ArgumentException("Key must be 32 bytes in Base64 format");
|
||||||
|
|
||||||
|
if (ivBytes.Length != 16)
|
||||||
|
throw new ArgumentException("IV must be 16 bytes in Base64 format");
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Key or IV is not valid Base64 string");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string EncryptMobileNumber(string mobileNumber)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(mobileNumber))
|
||||||
|
throw new ArgumentException("Mobile number cannot be null or empty");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] key = Convert.FromBase64String(_key);
|
||||||
|
byte[] iv = Convert.FromBase64String(_iv);
|
||||||
|
byte[] plainTextBytes = Encoding.UTF8.GetBytes(mobileNumber);
|
||||||
|
|
||||||
|
using (Aes aesAlg = Aes.Create())
|
||||||
|
{
|
||||||
|
aesAlg.Key = key;
|
||||||
|
aesAlg.IV = iv;
|
||||||
|
aesAlg.Mode = CipherMode.ECB;
|
||||||
|
aesAlg.Padding = PaddingMode.PKCS7;
|
||||||
|
|
||||||
|
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
|
||||||
|
|
||||||
|
using (MemoryStream msEncrypt = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
|
||||||
|
{
|
||||||
|
csEncrypt.Write(plainTextBytes, 0, plainTextBytes.Length);
|
||||||
|
csEncrypt.FlushFinalBlock();
|
||||||
|
|
||||||
|
byte[] encryptedBytes = msEncrypt.ToArray();
|
||||||
|
return Convert.ToBase64String(encryptedBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"Encryption failed: {ex.Message}", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string DecryptMobileNumber(string encryptedMobileNumber)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(encryptedMobileNumber))
|
||||||
|
throw new ArgumentException("Encrypted mobile number cannot be null or empty");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] key = Convert.FromBase64String(_key);
|
||||||
|
byte[] iv = Convert.FromBase64String(_iv);
|
||||||
|
byte[] cipherTextBytes = Convert.FromBase64String(encryptedMobileNumber);
|
||||||
|
|
||||||
|
using (Aes aesAlg = Aes.Create())
|
||||||
|
{
|
||||||
|
aesAlg.Key = key;
|
||||||
|
aesAlg.IV = iv;
|
||||||
|
aesAlg.Mode = CipherMode.ECB;
|
||||||
|
aesAlg.Padding = PaddingMode.PKCS7;
|
||||||
|
|
||||||
|
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
|
||||||
|
|
||||||
|
using (MemoryStream msDecrypt = new MemoryStream(cipherTextBytes))
|
||||||
|
{
|
||||||
|
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
|
||||||
|
{
|
||||||
|
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
|
||||||
|
{
|
||||||
|
return srDecrypt.ReadToEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"Decryption failed: {ex.Message}", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,10 @@
|
|||||||
"GwUrl": "https://fogw.kbs1.ir",
|
"GwUrl": "https://fogw.kbs1.ir",
|
||||||
//"GwUrl": "https://localhost:34781",
|
//"GwUrl": "https://localhost:34781",
|
||||||
"DownloadUrl": "https://dl.afrino.co",
|
"DownloadUrl": "https://dl.afrino.co",
|
||||||
|
"EncryptionSettings": {
|
||||||
|
"Key": "kmcQ3XTmH4mrdh8VHziuscyf8LLYjG//Kyni81nH/0E=",
|
||||||
|
"IV": "1wyF3Tt142MOkCpIyCxh/g=="
|
||||||
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
|
|||||||
Reference in New Issue
Block a user