Foros del Web » Programando para Internet » ASPX (.net) »

Encriptar Desencriptar String .....

Estas en el tema de Encriptar Desencriptar String ..... en el foro de ASPX (.net) en Foros del Web. Como hago esto?¿?...
  #1 (permalink)  
Antiguo 07/11/2006, 13:22
Avatar de shumito  
Fecha de Ingreso: mayo-2006
Mensajes: 248
Antigüedad: 18 años
Puntos: 0
Encriptar Desencriptar String .....

Como hago esto?¿?
  #2 (permalink)  
Antiguo 07/11/2006, 13:33
Avatar de rodri  
Fecha de Ingreso: febrero-2005
Mensajes: 406
Antigüedad: 19 años, 2 meses
Puntos: 2
Puedes utilizar un proveedor de encripción simétrico (DPAPI) con el Cryptography Application Block.

http://davidhayden.com/blog/dave/arc...3/02/2870.aspx

http://msdn.microsoft.com/library/de...ml/crypto1.asp

saludos
__________________
0.o Rodri
  #3 (permalink)  
Antiguo 07/11/2006, 15:00
Avatar de shumito  
Fecha de Ingreso: mayo-2006
Mensajes: 248
Antigüedad: 18 años
Puntos: 0
esto encontre...saludos !

public string EncriptaTexto(string Cadena,byte[] Key, byte[] IV)
{
string TextoEncriptado = string.Empty;

// Create or open the specified file.
MemoryStream mStream = new MemoryStream();

// Create a new Rijndael object.
Rijndael RijndaelAlg = Rijndael.Create();

// Create a CryptoStream using the FileStream
// and the passed key and initialization vector (IV).
CryptoStream cStream = new CryptoStream(mStream, RijndaelAlg.CreateEncryptor(Key, IV),
CryptoStreamMode.Write);

// Create a StreamWriter using the CryptoStream.
StreamWriter sWriter = new StreamWriter(cStream);

try
{
// Write the data to the stream
// to encrypt it.
sWriter.Write(Cadena);
TextoEncriptado = Convert.ToBase64String(mStream.ToArray());

}
catch (Exception ex)
{
TextoEncriptado = ex.Message;
}
finally
{
sWriter.Close();
cStream.Close();
mStream.Close();
}
return TextoEncriptado;
}

public string DesencriptaTexto(string Cadena, byte[] Key, byte[] IV)
{
string TextoDesencriptado = string.Empty;

// Create or open the specified file.
MemoryStream mStream = new MemoryStream(Convert.FromBase64String(Cadena));

// Crea un nuevo Rijndael object.
Rijndael RijndaelAlg = Rijndael.Create();

// Create a CryptoStream using the FileStream
// and the passed key and initialization vector (IV).
CryptoStream cStream = new CryptoStream(mStream, RijndaelAlg.CreateDecryptor(Key, IV),
CryptoStreamMode.Read);

// Create a StreamWriter using the CryptoStream.
StreamReader sReader = new StreamReader(cStream);
try
{
// escribo el texto a desencriptar
TextoDesencriptado = sReader.ReadToEnd();
}
catch (Exception ex)
{
TextoDesencriptado = ex.Message;
}
finally
{
// cierro todos los streams
sReader.Close();
cStream.Close();
mStream.Close();
}
return TextoDesencriptado;
}
}
  #4 (permalink)  
Antiguo 13/11/2006, 15:19
 
Fecha de Ingreso: enero-2004
Mensajes: 310
Antigüedad: 20 años, 3 meses
Puntos: 0
http://www.mistrucos.net/truco-visua...cion-509_3.htm
__________________
Un saludo,
Trucos
Videos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:23.