Commit inicial: ITCA_API_SAP_WMS (.NET Core 3.1)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
GeorgeandClaude Sonnet 5.5 committed 2026-10-05 17:53:41 -05:00
commit 2b82744eb8
168 files changed
+11066

No files matched your search

+223
View File
@@ -0,0 +1,223 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace Net.CrossCotting
{
//Advanced Encryption Standard(AES),
//también conocido como Rijndael(pronunciado “Rain Doll” en inglés),
//es un esquema de cifrado por bloques adoptado como un estándar de
//cifrado por el gobierno de los Estados Unidos.
//El AES fue anunciado por el Instituto
//Nacional de Estándares y Tecnología (NIST) como FIPS PUB 197 de los
//Estados Unidos (FIPS 197) el 26 de noviembre de 2001 después de un
//proceso de estandarización que duró 5 años.Se transformó en un estándar
//efectivo el 26 de mayo de 2002. Desde 2006, el AES es uno de los algoritmos
//más populares usados en criptografía simétrica.
public static class EncriptaHelper
{
private static string tokenFromUI = "123456$#@$^@1$B@";
private static Rfc2898DeriveBytes GetSecretKey()
{
const string encryptionKey = "r3turn-d3-$up3rm4n-!!";
byte[] salt = Encoding.UTF8.GetBytes(encryptionKey);
var secretKey = new Rfc2898DeriveBytes(encryptionKey, salt);
return secretKey;
}
/// <summary>
/// Encripta cualquier texto usando el algoridmo Rijndael.
/// </summary>
/// <param name="rawText">texto a encryptar</param>
/// <returns>Array de bytes con el texto encriptado</returns>
public static byte[] EncryptToByte(string rawText)
{
var rijndaelCipher = new RijndaelManaged();
byte[] rawTextData = Encoding.UTF8.GetBytes(rawText);
Rfc2898DeriveBytes secretKey = GetSecretKey();
using (var encryptor = rijndaelCipher.CreateEncryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))
{
using (var memoryStream = new MemoryStream())
{
using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
{
cryptoStream.Write(rawTextData, 0, rawTextData.Length);
cryptoStream.FlushFinalBlock();
return memoryStream.ToArray();
}
}
}
}
/// <summary>
/// Desencripta un texto previamente encriptado con el algoritmo Rijndael.
/// </summary>
/// <param name="encryptByte">Array de bytes del texto encriptado a desencriptar.</param>
/// <returns>Texto desencriptado.</returns>
public static string Decrypt(byte[] encryptByte)
{
try
{
var rijndaelCipher = new RijndaelManaged();
Rfc2898DeriveBytes secretKey = GetSecretKey();
using (ICryptoTransform decryptor = rijndaelCipher.CreateDecryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))
{
using (var memoryStream = new MemoryStream(encryptByte))
{
using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
{
var plainText = new byte[encryptByte.Length];
int decryptedCount = cryptoStream.Read(plainText, 0, plainText.Length);
return Encoding.UTF8.GetString(plainText, 0, decryptedCount);
}
}
}
}
catch
{
return null;
}
}
public static string DecryptStringAES(string cipherText)
{
var keybytes = Encoding.UTF8.GetBytes(tokenFromUI);
var iv = Encoding.UTF8.GetBytes(tokenFromUI);
var encrypted = Convert.FromBase64String(cipherText);
var decriptedFromJavascript = DecryptStringFromBytes(encrypted, keybytes, iv);
return decriptedFromJavascript;
}
private static string DecryptStringFromBytes(byte[] cipherText, byte[] key, byte[] iv)
{
// Check arguments.
if (cipherText == null || cipherText.Length <= 0)
{
throw new ArgumentNullException("cipherText");
}
if (key == null || key.Length <= 0)
{
throw new ArgumentNullException("key");
}
if (iv == null || iv.Length <= 0)
{
throw new ArgumentNullException("key");
}
// Declare the string used to hold
// the decrypted text.
string plaintext = null;
// Create an RijndaelManaged object
// with the specified key and IV.
using (var rijAlg = new RijndaelManaged())
{
//Settings
rijAlg.Mode = CipherMode.CBC;
rijAlg.Padding = PaddingMode.PKCS7;
rijAlg.FeedbackSize = 128;
rijAlg.Key = key;
rijAlg.IV = iv;
// Create a decrytor to perform the stream transform.
var decryptor = rijAlg.CreateDecryptor(rijAlg.Key, rijAlg.IV);
try
{
// Create the streams used for decryption.
using (var msDecrypt = new MemoryStream(cipherText))
{
using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (var srDecrypt = new StreamReader(csDecrypt))
{
// Read the decrypted bytes from the decrypting stream
// and place them in a string.
plaintext = srDecrypt.ReadToEnd();
}
}
}
}
catch
{
plaintext = "keyError";
}
}
return plaintext;
}
public static string EncryptStringAES(string plainText)
{
var keybytes = Encoding.UTF8.GetBytes(tokenFromUI);
var iv = Encoding.UTF8.GetBytes(tokenFromUI);
var encryoFromJavascript = EncryptStringToBytes(plainText, keybytes, iv);
return Convert.ToBase64String(encryoFromJavascript);
}
private static byte[] EncryptStringToBytes(string plainText, byte[] key, byte[] iv)
{
// Check arguments.
if (plainText == null || plainText.Length <= 0)
{
throw new ArgumentNullException("plainText");
}
if (key == null || key.Length <= 0)
{
throw new ArgumentNullException("key");
}
if (iv == null || iv.Length <= 0)
{
throw new ArgumentNullException("key");
}
byte[] encrypted;
// Create a RijndaelManaged object
// with the specified key and IV.
using (var rijAlg = new RijndaelManaged())
{
rijAlg.Mode = CipherMode.CBC;
rijAlg.Padding = PaddingMode.PKCS7;
rijAlg.FeedbackSize = 128;
rijAlg.Key = key;
rijAlg.IV = iv;
// Create a decrytor to perform the stream transform.
var encryptor = rijAlg.CreateEncryptor(rijAlg.Key, rijAlg.IV);
// Create the streams used for encryption.
using (var msEncrypt = new MemoryStream())
{
using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (var swEncrypt = new StreamWriter(csEncrypt))
{
//Write all data to the stream.
swEncrypt.Write(plainText);
}
encrypted = msEncrypt.ToArray();
}
}
}
// Return the encrypted bytes from the memory stream.
return encrypted;
}
}
}
+15
View File
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="iTextSharp.LGPLv2.Core" Version="1.6.9" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Net.Business.Entities\Net.Business.Entities.csproj" />
</ItemGroup>
</Project>
+84
View File
@@ -0,0 +1,84 @@
using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
namespace Net.CrossCotting
{
public class PageEventHelper : PdfPageEventHelper
{
// This is the contentbyte object of the writer
PdfContentByte cb;
// we will put the final number of pages in a template
PdfTemplate template;
PdfTemplate templateHeader;
// this is the BaseFont we are going to use for the header / footer
BaseFont bf = null;
// This keeps track of the creation time
DateTime PrintTime = DateTime.Now;
#region Properties
private string _Title;
public string Title
{
get { return _Title; }
set { _Title = value; }
}
#endregion
// we override the onOpenDocument method
public override void OnOpenDocument(PdfWriter writer, Document document)
{
try
{
PrintTime = DateTime.Now;
bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb = writer.DirectContent;
template = cb.CreateTemplate(document.PageSize.Width, 80);
templateHeader = cb.CreateTemplate(document.PageSize.Width, 80);
}
catch (DocumentException)
{
}
catch (System.IO.IOException)
{
}
}
public override void OnStartPage(PdfWriter writer, Document document)
{
base.OnStartPage(writer, document);
Rectangle pageSize = document.PageSize;
if (Title != string.Empty)
{
cb.BeginText();
cb.SetFontAndSize(bf, 15);
cb.SetRgbColorFill(50, 50, 200);
cb.SetColorFill(new BaseColor(103, 93, 152));
cb.SetTextMatrix(pageSize.GetLeft(40), pageSize.GetTop(40));
cb.ShowText(Title);
cb.EndText();
}
}
public override void OnEndPage(PdfWriter writer, Document document)
{
base.OnEndPage(writer, document);
int pageN = writer.PageNumber;
Rectangle pageSize = document.PageSize;
cb.SetRgbColorFill(100, 100, 100);
cb.BeginText();
cb.SetFontAndSize(bf, 8);
cb.SetTextMatrix(pageSize.GetLeft(40), pageSize.GetBottom(30));
cb.EndText();
}
public override void OnCloseDocument(PdfWriter writer, Document document)
{
base.OnCloseDocument(writer, document);
template.BeginText();
template.SetFontAndSize(bf, 8);
template.SetTextMatrix(0, 0);
template.EndText();
}
}
}
+58
View File
@@ -0,0 +1,58 @@
using Net.Business.Entities;
using System.Collections.Generic;
using System.Net;
namespace Net.CrossCotting
{
public class ResultadoTransaccion<T>
{
BE_ResultadoTransaccion<T> _resultadoTransaccion = new BE_ResultadoTransaccion<T>();
public ResultadoTransaccion(string NombreMetodo, string NombreAplicacion)
{
_resultadoTransaccion.MethodName = NombreMetodo;
_resultadoTransaccion.AppName = NombreAplicacion;
}
public BE_ResultadoTransaccion<T> GetInformacionResultado(int IdRegistro, int ResultadoCodigo, string ResultadoDescripcion, IEnumerable<T> ListData)
{
_resultadoTransaccion.DocEntry = IdRegistro;
_resultadoTransaccion.StatusCode = ResultadoCodigo;
_resultadoTransaccion.Message = ResultadoDescripcion;
_resultadoTransaccion.ListData = ListData;
return _resultadoTransaccion;
}
public BE_ResultadoTransaccion<T> GetInformacionResultado(int DocEntry, string DocNum, string ResultadoDescripcion, T Data)
{
_resultadoTransaccion.DocEntry = DocEntry;
_resultadoTransaccion.DocNum = DocNum;
_resultadoTransaccion.StatusCode = (int)(HttpStatusCode.OK);
_resultadoTransaccion.Message = ResultadoDescripcion;
_resultadoTransaccion.Data = Data;
return _resultadoTransaccion;
}
public BE_ResultadoTransaccion<T> GetInformacionResultado(string ResultadoDescripcion, T Data)
{
_resultadoTransaccion.DocEntry = null;
_resultadoTransaccion.StatusCode = (int)HttpStatusCode.InternalServerError;
_resultadoTransaccion.Message = "";
_resultadoTransaccion.Error = ResultadoDescripcion;
_resultadoTransaccion.Data = Data;
return _resultadoTransaccion;
}
public BE_ResultadoTransaccion<T> GetInformacionResultado(int IdRegistro, int ResultadoCodigo, string ResultadoDescripcion)
{
_resultadoTransaccion.DocEntry = IdRegistro;
_resultadoTransaccion.StatusCode = ResultadoCodigo;
_resultadoTransaccion.Message = ResultadoDescripcion;
return _resultadoTransaccion;
}
}
}
+118
View File
@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Xml.Serialization;
namespace Net.CrossCotting
{
public class Serializador
{
#region xml
public bool SerializarXml<T>(T entidad, Stream stm)
{
bool result = false;
try
{
XmlSerializer ser = new XmlSerializer(typeof(T));
ser.Serialize(stm, entidad);
result = true;
}
catch (Exception)
{
throw;
}
return result;
}
public T DeserializarXml<T>(Stream entidad) where T : class
{
T result = null;
entidad.Position = 0;
XmlSerializer ser = new XmlSerializer(typeof(T));
result = ser.Deserialize(entidad) as T;
return result;
}
#endregion
#region binario
public bool SerializarBinario<T>(T entidad, Stream stm)
{
bool result = false;
try
{
BinaryFormatter serilializador = new BinaryFormatter();
serilializador.Serialize(stm, entidad);
result = true;
}
catch (Exception)
{
throw;
}
return result;
}
public T DeserializarBinario<T>(Stream entidad) where T : class
{
T Result = null;
try
{
entidad.Position = 0;
BinaryFormatter serializador = new BinaryFormatter();
Result = serializador.Deserialize(entidad) as T;
}
catch (Exception)
{
throw;
}
return Result;
}
#endregion
#region json
public bool SerializarJson<T>(T entidad, Stream stm)
{
bool result = false;
try
{
// ReSharper disable once SuggestUseVarKeywordEvident
DataContractJsonSerializer jentidad = new DataContractJsonSerializer(typeof(T));
jentidad.WriteObject(stm, entidad);
result = true;
}
catch (Exception)
{
throw;
}
return result;
}
public T DeserializarJson<T>(Stream entidad) where T : class
{
T result = null;
try
{
entidad.Position = 0;
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
result = (T)ser.ReadObject(entidad);
}
catch (Exception)
{
throw;
}
return result;
}
#endregion
}
}
+65
View File
@@ -0,0 +1,65 @@
using System;
namespace Net.CrossCotting
{
public class Utils
{
public static DateTime DateTimeEmpty()
{
return new DateTime(1, 1, 1, 0, 0, 0);
}
public static DateTime GetFechaHoraInicioActual(DateTime? fecha)
{
DateTime? data;
data = fecha;
if (fecha == null || fecha.Equals(DateTimeEmpty()))
{
data = new DateTime(DateTime.Now.Year, 1, DateTime.Now.Day, 0, 0, 0);
}
else
{
data = new DateTime(((DateTime)fecha).Year, ((DateTime)fecha).Month, ((DateTime)fecha).Day, 0, 0, 0);
}
return (DateTime)data;
}
public static DateTime GetFechaHoraFinActual(DateTime? fecha)
{
DateTime? data;
data = fecha;
if (fecha == null || fecha.Equals(DateTimeEmpty()))
{
data = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);
}
else
{
data = new DateTime(((DateTime)fecha).Year, ((DateTime)fecha).Month, ((DateTime)fecha).Day, 23, 59, 59);
}
return (DateTime)data;
}
public static string GenerarCodigoAleatorio()
{
Random obj = new Random();
string sCadena = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
int longitud = sCadena.Length;
char cletra;
int nlongitud = 30;
string sNuevacadena = string.Empty;
for (int i = 0; i < nlongitud; i++)
{
cletra = sCadena[obj.Next(nlongitud)];
sNuevacadena += cletra.ToString();
}
return sNuevacadena;
}
}
}