using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Security.Cryptography; using System.ComponentModel; using System.IO; using Microsoft.VisualBasic; using Microsoft.Extensions.Configuration; namespace DAVIVIENDA.SUGESE.Util { public class Encripta { private string GBPassword = string.Empty; private string LOGeneraKey = string.Empty; readonly IConfiguration _Configuration; public Encripta(IConfiguration Configuration) { _Configuration = Configuration; GBPassword = _Configuration.GetSection("ConnectionDbs").GetSection("GBPassword").Value; LOGeneraKey = _Configuration.GetSection("ConnectionDbs").GetSection("LOGeneraKey").Value; } /// /// /// /// /// /// /// public String DecryptString(String InputString, CipherMode CyphMode = CipherMode.ECB) { String SecretKey = LOGeneraKey; if (InputString == string.Empty) { return ""; } else { TripleDESCryptoServiceProvider Des = new TripleDESCryptoServiceProvider(); byte[] InputbyteArray = new byte[Convert.ToInt32(InputString.Length / 2 - 1) + 1]; MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider(); Des.Key = hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(SecretKey)); Des.Mode = CyphMode; //Put the input string into the byte array int X = 0; for (X = 0; X <= InputbyteArray.Length - 1; X++) { Int32 IJ = (Convert.ToInt32(InputString.Substring(X * 2, 2), 16)); ByteConverter BT = new ByteConverter(); InputbyteArray[X] = new byte(); InputbyteArray[X] = Convert.ToByte(BT.ConvertTo(IJ, typeof(byte))); } MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, Des.CreateDecryptor(), CryptoStreamMode.Write); //Flush the data through the crypto stream into the memory stream cs.Write(InputbyteArray, 0, InputbyteArray.Length); cs.FlushFinalBlock(); ////Get the decrypted data back from the memory stream StringBuilder ret = new StringBuilder(); byte[] B = ms.ToArray(); ms.Close(); int I = 0; for (I = 0; I <= Information.UBound(B); I++) { ret.Append(Strings.Chr(B[I])); } return ret.ToString(); } } } }