cdn
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace VizhTalk.BuildingBlocks.Domain;
|
||||
|
||||
public class EncryptionIdHelper
|
||||
{
|
||||
private const string Alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
public static string Encrypt(string input)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(input);
|
||||
|
||||
// تبدیل بایتها به عدد بزرگ
|
||||
var number = new System.Numerics.BigInteger(bytes);
|
||||
|
||||
// اگر منفی شد، مثبتش کن
|
||||
if (number < 0) number = -number;
|
||||
|
||||
// تبدیل به Base62
|
||||
StringBuilder result = new StringBuilder();
|
||||
while (number > 0)
|
||||
{
|
||||
result.Insert(0, Alphabet[(int)(number % 62)]);
|
||||
number /= 62;
|
||||
}
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
public static string Decrypt(string encoded)
|
||||
{
|
||||
System.Numerics.BigInteger number = 0;
|
||||
foreach (char c in encoded)
|
||||
{
|
||||
number = number * 62 + Alphabet.IndexOf(c);
|
||||
}
|
||||
|
||||
// تبدیل دوباره به بایت
|
||||
byte[] bytes = number.ToByteArray();
|
||||
|
||||
// رشته اصلی
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
}
|
||||
@@ -17,4 +17,6 @@ public class BusinessRuleValidationException : Exception
|
||||
{
|
||||
return $"{BrokenRule.GetType().FullName}: {BrokenRule.Message}";
|
||||
}
|
||||
public string GetFullName()
|
||||
=> BrokenRule.GetType()?.FullName!;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace VizhTalk.BuildingBlocks.Domain;
|
||||
|
||||
public abstract class TypedIdValueBase<T> : IEquatable<TypedIdValueBase<T>> , ITypeIdValueBase
|
||||
public abstract class TypedIdValueBase<T> : IEquatable<TypedIdValueBase<T>>, ITypeIdValueBase
|
||||
{
|
||||
public T Value { get; }
|
||||
|
||||
protected TypedIdValueBase(T value)
|
||||
{
|
||||
|
||||
|
||||
if (EqualityComparer<T>.Default.Equals(value, default(T)))
|
||||
{
|
||||
throw new InvalidOperationException($"Id value cannot be empty ! : id is {value}");
|
||||
@@ -32,7 +32,7 @@ public abstract class TypedIdValueBase<T> : IEquatable<TypedIdValueBase<T>> , IT
|
||||
|
||||
public bool Equals(TypedIdValueBase<T>? other)
|
||||
{
|
||||
if(other == null)
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return EqualityComparer<T>.Default.Equals(this.Value, other.Value);
|
||||
@@ -59,5 +59,7 @@ public abstract class TypedIdValueBase<T> : IEquatable<TypedIdValueBase<T>> , IT
|
||||
return !(x == y);
|
||||
}
|
||||
}
|
||||
public interface ITypeIdValueBase { }
|
||||
public interface ITypeIdValueBase
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user