namespace Helper
{
using System.Configuration;
using System.Text;
///
/// Clase para la encriptación.
///
public sealed class CryptographyManager : CryptographyFoundation
{
///
/// The global secret key.
///
private readonly byte[] globalSecretKey;
///
/// The iv.
///
private readonly byte[] iv;
///
/// The global initialization vector.
///
private readonly string globalInitializationVector;
///
/// Inicializa una nueva instancia de la clase .
///
public CryptographyManager()
{
this.globalSecretKey = Encoding.ASCII.GetBytes(ConfigurationManager.AppSettings["globalSecretKey"].ToString());// Encoding.ASCII.GetBytes("12EstaClave34es56dificil489ssswf");
this.globalInitializationVector = ConfigurationManager.AppSettings["globalInitializationVector"].ToString(); // Debe ser de 16 letras vector de inicialización ( IV ) para el algoritmo simétrico
this.iv = Encoding.ASCII.GetBytes(this.globalInitializationVector);
}
///
/// Encripta el texto enviado usando el algoritmo "Rijndael"
///
///
/// El texto sin codificar.
///
///
/// El texto codificado. Tipo .
///
public string Encriptar(string textToEncrypt)
{
var encryptor = this.GetEncryptor(this.globalSecretKey, this.iv);
var result = this.Encriptador(textToEncrypt, encryptor);
return this.ReverseCase(result);
}
///
/// Decodifica el texto el algoritmo "Rijndael"
///
///
/// El texto decodificado.
///
///
/// Texto decodificado. Tipo .
///
public string Desencriptar(string encryptedText)
{
var decryptor = this.GetDecryptor(this.globalSecretKey, this.iv);
return this.Desencriptador(this.ReverseCase(encryptedText), decryptor);
}
}
}