/// <summary> /// Metodo que se encarga de deserializar un archivo de datos desencriptandolo o no dependiendo de la /// decición del implementador. /// </summary> /// <param name="path">Ruta del archivo del cual se leen los datos</param> /// <param name="secured">Indica si se desencripta o no la deserializacion del objeto</param> /// <returns>El objeto deserializado (integrado)</returns> public static Object integrate(string path, bool secured) { FileStream theFile = null; Object Daffy_Duck = null; BinaryFormatter bf = null; try { theFile = new FileStream(path, FileMode.Open, FileAccess.Read); bf = new BinaryFormatter(); } catch (Exception) { throw; } if (secured) { StreamReader theReader = new StreamReader(theFile); string Daffy_Dust = theReader.ReadToEnd(); Cryptos Koder = new Cryptos(Cryptos.algorithmType.DES); Daffy_Dust = Koder.Decrypting(Daffy_Dust); byte[] binaryData = System.Convert.FromBase64String(Daffy_Dust); MemoryStream theMemory = new MemoryStream(binaryData); Daffy_Duck = bf.Deserialize(theMemory); } else { Daffy_Duck = bf.Deserialize(theFile); } theFile.Close(); return Daffy_Duck; }
public UserResponse getUserByLogin(UserRequest request) { UserResponse response = new UserResponse(); var accountFound = Olympus._Nerv.UserAccounts.Where(x => x.Account.ToUpper() == request.UserName.ToUpper()).SingleOrDefault(); if (accountFound != null) { var cypher = new Cryptos(Cryptos.algorithmType.DES); if (cypher.Encrypt(request.Password).Equals(accountFound.Password)) { // Map the UserAccount Olympus._Nerv.UserAccounts.Detach(accountFound); response.UserAccount = Mapper.Map<UserAccount, UserAccountDto>(accountFound); } } return response; }
/// <summary> /// Se encarga de encriptar un flujo de datos mediante la clase EncDec /// </summary> /// <remarks> /// De momento se utiliza el algoritmo DESCryptoServiceProvider, se espera mas adelante modificar /// la clase para que pueda usar cualquiera de los tres metodos conocidos o uno propio, tal como /// permite la clase EncDec /// </remarks> /// <param name="theMemory">Flujo de datos que se desea encriptar</param> /// <returns>Una cadena de texto encriptada mediante el algoritmo DESCryptoServiceProvider</returns> private static string encryption(MemoryStream theMemory) { string base64String = ""; // Se crea un Encriptador Cryptos Koder = new Cryptos(Cryptos.algorithmType.DES); // Se extraen los Binario del Memorystream byte[] binaryData = theMemory.GetBuffer(); // Se convierte de Binario a String base64String = Convert.ToBase64String(binaryData, 0, binaryData.Length); // Se encrypta el objeto serializado base64String = Koder.Encrypt(base64String); return base64String; }