Ver Mensaje Individual
  #17 (permalink)  
Antiguo 06/04/2005, 10:22
Avatar de phinojosa
phinojosa
 
Fecha de Ingreso: agosto-2004
Ubicación: Guayaquil-Ecuador
Mensajes: 145
Antigüedad: 22 años, 2 meses
Puntos: 2
Con este código cargo en DataGrid....

Código PHP:

SqlConnection conn 
= new SqlConnection(conexion);
            
            
sql=         " SELECT coClinica,txClinica ";
            
sql=sql + " FROM ";
            
sql=sql + " tblClClinica ";
            
sql=sql + " WHERE  1=1 " + Session["criterio"].ToString();
            
sql=sql + " order by 1 ";
            
            
SqlDataAdapter daBusqueda = new SqlDataAdapter(sql, conn);
            
DataSet ds = new DataSet();
            
daBusqueda.Fill(ds, "tblClClinica");

            
this.dtgClinicas.CurrentPageIndex=0;

            
ds.Tables[0].Columns.Add("coCliEnc");
            
DataTable tblRecorre;
            
tblRecorre = ds.Tables[0];
            foreach(
DataRow dr    in tblRecorre.Rows)
            {
                
dr["coCliEnc"]=FuncGenerales.Encrypt(dr["coClinica"].ToString(),"&%#@?,:*");
            }
            
this.dtgClinicas.DataSource = ds;
            
this.dtgClinicas.DataBind();
            
Session["ds"]=ds; 
Si te das cuenta la llave es..... "&%#@?,:*"

Y asi lo envio hacia la otra página en el evento ItemCommand

Código PHP:

string id
, url,modo ;
            if (
e.CommandName.Equals ("Consultar"))
            {
                
id = e.Item.Cells[1].Text.Trim();
                
modo=FuncGenerales.Encrypt("C","&%#@?,:*");
                
url="AgrClinicaDet.aspx?id="+id + " &modo=" + modo;
                
Response.Redirect (url);
            }
            if (
e.CommandName.Equals ("Modificar"))
            {
                
id = e.Item.Cells[1].Text.Trim();
                
modo=FuncGenerales.Encrypt("M","&%#@?,:*");
                
url="AgrClinicaDet.aspx?id="+id + "&modo=" + modo;
                
Response.Redirect (url);
            }
            if (
e.CommandName.Equals ("Eliminar"))
            {
                
id = e.Item.Cells[1].Text.Trim();
                
modo=FuncGenerales.Encrypt("E","&%#@?,:*");
                
url="AgrClinicaDet.aspx?id="+id + "&modo=" + modo;
                
Response.Redirect (url);
            } 
Y de esta forma lo desencripto en la página destino....
Código PHP:

Session
["modo"]=FuncGenerales.Decrypt(Request.QueryString["modo"],"&%#@?,:*");
                
id=FuncGenerales.Decrypt(Request.QueryString["id"],"&%#@?,:*"); 
Los métodos de encriptación y Desencriptación Los detallo a continuación

Código PHP:
public static String Encrypt(String strText, String strEncrKey )
        {
            
byte[] bKey = new byte [8] ;
            
byte[] IV = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};

            try 
            {
                
bKey = System.Text.Encoding.UTF8.GetBytes( strEncrKey.Substring(0,8));
                
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                
Byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
                
MemoryStream ms = new MemoryStream();
                
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(bKey, IV), CryptoStreamMode.Write);
                
cs.Write(inputByteArray, 0, inputByteArray.Length);
                
cs.FlushFinalBlock();
                return 
Convert.ToBase64String(ms.ToArray());

            }
            catch (
Exception ex) 
            {
                return 
ex.Message.ToString();
            }
        }


        public static 
String Decrypt(String strText, String strEncrKey )
        {
            
byte[] bKey = new byte [8] ;
            
byte[] IV = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};

            try 
            {
                
bKey = System.Text.Encoding.UTF8.GetBytes( strEncrKey.Substring(0,8));
                
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                
Byte[] inputByteArray = inputByteArray = Convert.FromBase64String(strText);
                
MemoryStream ms = new MemoryStream();
                
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(bKey, IV), CryptoStreamMode.Write);
                
cs.Write(inputByteArray, 0, inputByteArray.Length);
                
cs.FlushFinalBlock();
                
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
                return 
encoding.GetString(ms.ToArray());
            }
            catch (
Exception ex) 
            {
                return 
ex.Message.ToString();
            }
        } 
Te cuento que los he probado con los códigos
"00001","00002","00003","00004","00005","00006","0 0007","00008",
"00009","00010","00011","00012"

Funcionan con todos excepto con el código "00002"

Agradezco tu ayuda....