feat: implement core domain models, authentication service, and UI components for the attendance system
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Asistencia.Helpers;
|
||||
|
||||
public static class CryptoHelper
|
||||
{
|
||||
private static readonly byte[] Key = Encoding.UTF8.GetBytes("S4M_Pru3b4_2024!");
|
||||
private static readonly byte[] IV = new byte[16];
|
||||
|
||||
public static string Encriptar(string texto)
|
||||
{
|
||||
using var aes = Aes.Create();
|
||||
aes.Key = Key;
|
||||
aes.IV = IV;
|
||||
aes.Mode = CipherMode.CBC;
|
||||
aes.Padding = PaddingMode.PKCS7;
|
||||
|
||||
using var encryptor = aes.CreateEncryptor();
|
||||
using var ms = new MemoryStream();
|
||||
using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
|
||||
using (var writer = new StreamWriter(cs))
|
||||
{
|
||||
writer.Write(texto);
|
||||
}
|
||||
return Convert.ToBase64String(ms.ToArray());
|
||||
}
|
||||
|
||||
public static string Desencriptar(string textoEncriptado)
|
||||
{
|
||||
using var aes = Aes.Create();
|
||||
aes.Key = Key;
|
||||
aes.IV = IV;
|
||||
aes.Mode = CipherMode.CBC;
|
||||
aes.Padding = PaddingMode.PKCS7;
|
||||
|
||||
var buffer = Convert.FromBase64String(textoEncriptado);
|
||||
using var decryptor = aes.CreateDecryptor();
|
||||
using var ms = new MemoryStream(buffer);
|
||||
using var cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read);
|
||||
using var reader = new StreamReader(cs);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user