using System;
using System.Security.Cryptography;
namespace RijndaelManaged
{
/// <summary>
/// This class contains only 2 methods: Encrypt and Decrypt.
/// They both require two byte array parameters like the ones below.
///
///byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
///byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
/// </summary>
public class DsCrypt
{
public DsCrypt()
{
}
public string Encrypt(string s, byte[] key, byte[] iv)
{
System.Security.Cryptography.RijndaelManaged rij = new System.Security.Cryptography.RijndaelManaged();
rij.Key = key;
rij.IV = iv;
byte[] input = System.Text.Encoding.UTF8.GetBytes(s);
byte[] output = rij.CreateEncryptor().TransformFinalBlock(input, 0, input.Length);
return Convert.ToBase64String(output);
}
public string Decrypt(string s, byte[] key, byte[] iv)
{
System.Security.Cryptography.RijndaelManaged rij = new System.Security.Cryptography.RijndaelManaged();
rij.Key = key;
rij.IV = iv;
byte[] input = Convert.FromBase64String(s);
byte[] output = rij.CreateDecryptor().TransformFinalBlock(input, 0, input.Length);
return System.Text.Encoding.UTF8.GetString(output);
}
}
}