using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
Debemos declarar y no perder estas dos variables:
byte[] bClave =
Encoding.UTF8.GetBytes("b%`^x&amH~a!x@Y#c$p;J*M-e^L_");
byte[] bVector =
Encoding.UTF8.GetBytes("p$ctuW^%");
La función encripta una cadena de texto:
***********************************************************************
public string CifrarValor(string sValor)
{
string sResultado = string.Empty;
TripleDESCryptoServiceProvider oTripleDESC =
new TripleDESCryptoServiceProvider();
try
{
byte[] bIN = Encoding.UTF8.GetBytes(sValor);
using (MemoryStream oOutStream = new MemoryStream())
{
CryptoStream oCryptoStream =
new CryptoStream(oOutStream,
oTripleDESC.CreateEncryptor(bClave, bVector),
CryptoStreamMode.Write);
oCryptoStream.Write(bIN, 0, bIN.Length);
oCryptoStream.FlushFinalBlock();
sResultado = Convert.ToBase64String(oOutStream.ToArray());
}
}
catch (Exception ex)
{
throw new System.Exception(ex.Message, ex.InnerException);
}
return sResultado;
}

No hay comentarios:
Publicar un comentario