Semplice classe scritta in C# per criptare stringhe
public class Crypter
{
private const string chiave= "AxTYQWCvGTFRbgLL"; //16 byte
private const string iv = "QWExcfTyUxxLOafO"; //16 byte
public Crypter()
{
//
// TODO: Add constructor logic here
//
}
public static string Encode(string S)
{
RijndaelManaged rjm = new RijndaelManaged();
rjm.KeySize = 128;
rjm.BlockSize = 128;
rjm.Key = ASCIIEncoding.ASCII.GetBytes(chiave);
rjm.IV = ASCIIEncoding.ASCII.GetBytes(iv);
Byte[] input = Encoding.UTF8.GetBytes(S);
Byte[] output = rjm.CreateEncryptor().TransformFinalBlock(input, 0,
input.Length);
return Convert.ToBase64String(output);
}
public static string Decode(string S)
{
RijndaelManaged rjm = new RijndaelManaged();
rjm.KeySize = 128;
rjm.BlockSize = 128;
rjm.Key = ASCIIEncoding.ASCII.GetBytes(chiave);
rjm.IV = ASCIIEncoding.ASCII.GetBytes(iv);
try
{
Byte[] input = Convert.FromBase64String(S);
Byte[] output = rjm.CreateDecryptor().TransformFinalBlock(input, 0,
input.Length);
return Encoding.UTF8.GetString(output);
}
catch
{
return S;
}
}
}
posted @ martedì 14 giugno 2005 20:38