Using System;
Using System.IO;
Using System.Security.Cryptography;
Namespace Vavic
{
///
A summary description of the security.
///
public class Security
{
Const string key_64 = "Vavicapp";
Const string iv_64 = "Vavicapp"; Attention, it's 8 characters, 64 bits.
Public Security ()
{
//
TODO: Add constructor logic here
//
}
public static string Encode (String data)
{
byte[] Bykey = System.Text.ASCIIEncoding.ASCII.GetBytes (key_64);
byte[] Byiv = System.Text.ASCIIEncoding.ASCII.GetBytes (iv_64);
DESCryptoServiceProvider CryptoProvider = new DESCryptoServiceProvider ();
int i = cryptoprovider.keysize;
MemoryStream ms = new MemoryStream ();
CryptoStream CST = new CryptoStream (Ms,cryptoprovider.createencryptor (Bykey,byiv), cryptostreammode.write);
StreamWriter sw = new StreamWriter (CST);
Sw. Write (data);
Sw. Flush ();
Cst. FlushFinalBlock ();
Sw. Flush ();
Return convert.tobase64string (Ms. GetBuffer (), 0, (int) Ms. Length);
}
public static string Decode (String data)
{
byte[] Bykey = System.Text.ASCIIEncoding.ASCII.GetBytes (key_64);
byte[] Byiv = System.Text.ASCIIEncoding.ASCII.GetBytes (iv_64);
Byte[] Byenc;
Try
{
Byenc = convert.frombase64string (data);
}
Catch
{
return null;
}
DESCryptoServiceProvider CryptoProvider = new DESCryptoServiceProvider ();
MemoryStream ms = new MemoryStream (BYENC);
CryptoStream CST = new CryptoStream (Ms,cryptoprovider.createdecryptor (Bykey,byiv), cryptostreammode.read);
StreamReader sr = new StreamReader (CST);
return Sr. ReadToEnd ();
}
}
}