//public bool LoginUsuario(Usuario unUsuario, string Password) //{ // var pass = encriptarSHA1(Password); // var parametros = new Dictionary<string, object>(); // parametros.Add("@usuario", unUsuario.Alias); // parametros.Add("@password", pass); // Area area = new Area(); // var tablaDatos = conexion_bd.Ejecutar("dbo.Web_Login", parametros); // //TODO: refactorizar el corte de control // if (tablaDatos.Rows.Count > 0) // { // tablaDatos.Rows.ForEach(row => // { // //if (row.GetSmallintAsInt("Id_Funcionalidad") == 1) unUsuario.TienePermisosParaViaticos = true; // //if (row.GetSmallintAsInt("Id_Funcionalidad") == 2) unUsuario.TienePermisosParaSiCoI = true; // //if (row.GetSmallintAsInt("Id_Funcionalidad") == 3 || row.GetSmallintAsInt("Id_Funcionalidad") == 4) unUsuario.TienePermisosParaSACC = true; // //if (row.GetSmallintAsInt("Id_Funcionalidad") == 5) unUsuario.TienePermisosParaModil = true; // //unUsuario.FeaturesDescripcion.Add(row.GetString("Nombre_Funcionalidad")); // //var Asistentes = new List<Asistente>(); // //if (unUsuario.AreasAdministradas.FindAll(a => a.Id == row.GetSmallintAsInt("Id_Area")).Count == 0) // //{ // // List<DatoDeContacto> DatosDeContacto = new List<DatoDeContacto>(); // // unUsuario.Id = row.GetSmallintAsInt("Id_Usuario"); // // unUsuario.EsFirmante = row.GetSmallintAsInt("es_firmante") != 0; // // Asistente asistente = new Asistente(row.GetString("Nombre_Asistente"), // // row.GetString("Apellido_Asistente"), // // row.GetString("Cargo"), // // row.GetSmallintAsInt("Prioridad_Asistente"), // // row.GetString("Telefono_Asistente"), // // row.GetString("Telefono_Asistente"), //Falta cambiar por Fax // // row.GetString("Mail_Asistente")); // // Asistentes.Add(asistente); // // Responsable datos_responsable = new Responsable(row.GetString("Nombre_Responsable"), // // row.GetString("Apellido_Responsable"), // // row.GetString("Nombre_Asistente"), //Falta cambiar!!! // // row.GetString("Nombre_Asistente"), //Falta cambiar!!! // // row.GetString("Nombre_Asistente")); //Falta cambiar!!! // // DatoDeContacto dato_de_contacto = new DatoDeContacto(row.GetSmallintAsInt("Id_Dato_Area"), // // row.GetString("Descripcion_Dato_Area"), // // row.GetString("Dato_Area"), // // row.GetSmallintAsInt("Orden")); // // DatosDeContacto.Add(dato_de_contacto); // // unUsuario.AreasAdministradas.Add(new Area // // { // // Id = row.GetSmallintAsInt("Id_Area"), // // Nombre = row.GetString("nombre_area"), // // Direccion = row.GetString("direccion"), // // datos_del_responsable = datos_responsable, // // Asistentes = Asistentes, // // DatosDeContacto = DatosDeContacto, // // }); // //} // //else // //{ // // var area_existente = unUsuario.AreasAdministradas.Find(a => a.Id == row.GetSmallintAsInt("Id_Area")); // // if (!area_existente.Asistentes.Any(a => a.Apellido == row.GetString("Apellido_Asistente") && a.Descripcion_Cargo == row.GetString("Cargo"))) // // { // // Asistente asistente = new Asistente(row.GetString("Nombre_Asistente"), // // row.GetString("Apellido_Asistente"), // // row.GetString("Cargo"), // // row.GetSmallintAsInt("Prioridad_Asistente"), // // row.GetString("Telefono_Asistente"), // // row.GetString("Telefono_Asistente"),//Falta cambiar por Fax!!! // // row.GetString("Mail_Asistente")); // // area_existente.Asistentes.Add(asistente); // // } // // if (!area_existente.DatosDeContacto.Any(d => d.Id == row.GetSmallintAsInt("Id_Dato_Area") && d.Orden == row.GetSmallintAsInt("Orden"))) // // { // // DatoDeContacto nuevo_dato = new DatoDeContacto(row.GetSmallintAsInt("Id_Dato_Area"), // // row.GetString("Descripcion_Dato_Area"), // // row.GetString("Dato_Area"), // // row.GetSmallintAsInt("Orden")); // // area_existente.DatosDeContacto.Add(nuevo_dato); // // } // //} // }); // foreach (Area area_interna in AdministracionDeUsuarios.Autorizador.Instancia().AreasAdministradasPor(unUsuario)) // { // area_interna.DatosDeContacto.Sort((dato1, dato2) => dato1.esMayorQue(dato2)); // } // return true; // } // else // { // return false; // } //} private static string encriptarSHA1(string CadenaOriginal) { System.Security.Cryptography.HashAlgorithm hashValue = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(CadenaOriginal); byte[] byteHash = hashValue.ComputeHash(bytes); hashValue.Clear(); return(Convert.ToBase64String(byteHash)); }
/// <summary> /// SHA-1 /// </summary> /// <param name="str"></param> public static string SHA_1(string str) { var sha1Csp = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(str); byte[] bytHash = sha1Csp.ComputeHash(bytValue); sha1Csp.Clear(); string hashStr = ""; for (int counter = 0; counter < bytHash.Count(); counter++) { long i = bytHash[counter] / 16; var tempStr = ""; if (i > 9) { tempStr = ((char)(i - 10 + 0x41)).ToString(); } else { tempStr = ((char)(i + 0x30)).ToString(); } i = bytHash[counter] % 16; if (i > 9) { tempStr += ((char)(i - 10 + 0x41)).ToString(); } else { tempStr += ((char)(i + 0x30)).ToString(); } hashStr += tempStr; } return(hashStr); }
public string EncryptToSHA1(string str) { System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] str1 = System.Text.Encoding.UTF8.GetBytes(str); byte[] str2 = sha1.ComputeHash(str1); sha1.Clear(); (sha1 as IDisposable).Dispose(); return Convert.ToBase64String(str2); }
private string encriptar(string txt_plano) { System.Security.Cryptography.HashAlgorithm obj_hash = new System.Security.Cryptography.SHA1CryptoServiceProvider(); // Convertir el string original a un array de Bytes byte[] cadena_plana = System.Text.Encoding.UTF8.GetBytes(txt_plano); byte[] cadena_encrp = obj_hash.ComputeHash(cadena_plana); obj_hash.Clear(); return(Convert.ToBase64String(cadena_encrp)); }
public override byte[] digest() { //return md.digest(); cs.Close(); byte[] result = md.Hash; md.Clear(); init(); //Reinitiazing hash objects return(result); }
public static string Encriptar(string valor) { string clave; System.Security.Cryptography.SHA1CryptoServiceProvider provider = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(valor); byte[] inArray = provider.ComputeHash(bytes); provider.Clear(); clave = Convert.ToBase64String(inArray); return clave; }
public static string Encriptar(string valor) { string clave; System.Security.Cryptography.SHA1CryptoServiceProvider provider = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(valor); byte[] inArray = provider.ComputeHash(bytes); provider.Clear(); clave = Convert.ToBase64String(inArray); return(clave); }
public static string SHA1(string data) { // Hash the input string using SHA1 and output a base64 answer byte[] bdata = System.Text.ASCIIEncoding.ASCII.GetBytes(data); byte[] result = null; System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider(); result = sha.ComputeHash(bdata); sha.Clear(); return(Convert.ToBase64String(result)); }
public void ENCRIP(string txt_plano, int campo) { System.Security.Cryptography.HashAlgorithm obj_hash = new System.Security.Cryptography.SHA1CryptoServiceProvider(); // Convertir el string original a un array de Bytes byte[] cadena_plana = System.Text.Encoding.UTF8.GetBytes(txt_plano); byte[] cadena_encrp = obj_hash.ComputeHash(cadena_plana); obj_hash.Clear(); if (campo == 1) { textBox3.Text = (Convert.ToBase64String(cadena_encrp)); } else { textBox4.Text = (Convert.ToBase64String(cadena_encrp)); } }
public void Calc_SHA1() { System.IO.FileStream fs = new System.IO.FileStream( filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] bs = sha1.ComputeHash(fs); sha1.Clear(); fs.Close(); SHA1_hash = BitConverter.ToString(bs).ToLower().Replace("-", ""); }
public static String Signature(String Seed) { String output = String.Empty; if (AppLogic.AppConfig("Ogone.SHASignature").Length == 0) { return(output); } Byte[] clearBytes; Byte[] hashedBytes; clearBytes = System.Text.Encoding.UTF8.GetBytes(Seed + AppLogic.AppConfig("Ogone.SHASignature")); System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider(); sha1.ComputeHash(clearBytes); hashedBytes = sha1.Hash; sha1.Clear(); output = BitConverter.ToString(hashedBytes).Replace("-", "").ToUpper(); return(output); }
/// <summary> /// 计算SHA-1码 /// </summary> /// <param name="word">字符串</param> /// <param name="toUpper">返回哈希值格式 true:英文大写,false:英文小写</param> /// <returns></returns> public static string Hash_SHA_1(string word, bool toUpper = true) { try { System.Security.Cryptography.SHA1CryptoServiceProvider SHA1CSP = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(word); byte[] bytHash = SHA1CSP.ComputeHash(bytValue); SHA1CSP.Clear(); //根据计算得到的Hash码翻译为SHA-1码 string sHash = "", sTemp = ""; for (int counter = 0; counter < bytHash.Count(); counter++) { long i = bytHash[counter] / 16; if (i > 9) { sTemp = ((char)(i - 10 + 0x41)).ToString(); } else { sTemp = ((char)(i + 0x30)).ToString(); } i = bytHash[counter] % 16; if (i > 9) { sTemp += ((char)(i - 10 + 0x41)).ToString(); } else { sTemp += ((char)(i + 0x30)).ToString(); } sHash += sTemp; } //根据大小写规则决定返回的字符串 return(toUpper ? sHash : sHash.ToLower()); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static string SHA1(this string source) { if (string.IsNullOrEmpty(source)) { return(""); } else { System.Security.Cryptography.SHA1CryptoServiceProvider md5 = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(source); bytes = md5.ComputeHash(bytes); md5.Clear(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.Length; i++) { sb.Append(bytes[i].ToString("x2")); } return(sb.ToString()); } }
public static string SHA1_Real(string data) { // Hash the input string using SHA1 and output a hexadecimal answer byte[] bdata = System.Text.ASCIIEncoding.ASCII.GetBytes(data); byte[] result = null; System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider(); result = sha.ComputeHash(bdata); sha.Clear(); string result_s = ""; foreach (byte b in result) { result_s += String.Format("{0:x2}", b); } return(result_s); }
/// <summary> /// Método para encriptar un string. En este caso se usa para el Pass. /// </summary> /// <param name="password">Contraseña a encriptar</param> /// <returns>Cadena encriptada</returns> private static string encrypt(string password) { System.Security.Cryptography.HashAlgorithm hashValue = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(password); byte[] byteHash = hashValue.ComputeHash(bytes); hashValue.Clear(); return (Convert.ToBase64String(byteHash)); }
public static string SHA1(string data) { // Hash the input string using SHA1 and output a base64 answer byte[] bdata = System.Text.ASCIIEncoding.ASCII.GetBytes(data); byte[] result = null; System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider(); result = sha.ComputeHash(bdata); sha.Clear(); return Convert.ToBase64String(result); }
public static string SHA1_Real(string data) { // Hash the input string using SHA1 and output a hexadecimal answer byte[] bdata = System.Text.ASCIIEncoding.ASCII.GetBytes(data); byte[] result = null; System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider(); result = sha.ComputeHash(bdata); sha.Clear(); string result_s = ""; foreach(byte b in result) result_s += String.Format("{0:x2}", b); return result_s; }
/// <summary> /// 计算SHA-1码 /// </summary> /// <param name="word">字符串</param> /// <param name="toUpper">返回哈希值格式 true:英文大写,false:英文小写</param> /// <returns></returns> public static string Hash_SHA_1(string word, bool toUpper = true) { try { System.Security.Cryptography.SHA1CryptoServiceProvider SHA1CSP = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(word); byte[] bytHash = SHA1CSP.ComputeHash(bytValue); SHA1CSP.Clear(); //根据计算得到的Hash码翻译为SHA-1码 string sHash = "", sTemp = ""; for (int counter = 0; counter < bytHash.Count(); counter++) { long i = bytHash[counter] / 16; if (i > 9) { sTemp = ((char)(i - 10 + 0x41)).ToString(); } else { sTemp = ((char)(i + 0x30)).ToString(); } i = bytHash[counter] % 16; if (i > 9) { sTemp += ((char)(i - 10 + 0x41)).ToString(); } else { sTemp += ((char)(i + 0x30)).ToString(); } sHash += sTemp; } //根据大小写规则决定返回的字符串 return toUpper ? sHash : sHash.ToLower(); } catch (Exception ex) { throw new Exception(ex.Message); } }