using
Microsoft.VisualBasic;
using System;
using System.IO;
using
System.Xml;
using
System.Text;
using
System.Security.Cryptography;
using
System.Data;
using
System.Configuration;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Xml.Linq;
public class clsEncryption
{
private byte[] key = { };
private byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
public
clsEncryption()
{
}
public string Decryptpwd(string
stringToDecrypt)
{
stringToDecrypt =
stringToDecrypt.Replace(" ", "+");
string
sEncryptionKey = "!*&@9876543210";
byte[]
inputByteArray = new byte[stringToDecrypt.Length
+ 1];
try
{
key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0,
8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms,
des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0,
inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return
encoding.GetString(ms.ToArray());
}
catch (Exception e)
{
//HttpContext.Current.Response.Redirect("~/PR_error.aspx");
throw;
return e.Message;
}
}
public string Encryptpwd(string
stringToEncrypt)
{
try
{
string
SEncryptionKey = "!*&@9876543210";
key = System.Text.Encoding.UTF8.GetBytes(SEncryptionKey.Substring(0,
8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[]
inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms,
des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0,
inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception e)
{
HttpContext.Current.Response.Redirect("~/Logout.aspx");
return e.Message;
}
}
public String Decrypt(String
strText)
{
int i, l, n,
pl;
String strPwd =
strText;// "";
char[] s, sp;
String strBuff = "";
if
(strPwd.Length > 0)
{
s = strText.ToCharArray();
l = s.Length;
sp = strPwd.ToCharArray();
pl = sp.Length;
for (i = 0; i
< l; i++)
{
n = (int)s[i];
n = n - ((int)sp[i % pl]);
strBuff = strBuff + (char)(n & 0xFF);
}
}
else
strBuff = strText;
return strBuff;
}
public String Encrypt(String
strText)
{
int i, n;
String strPwd =
strText;// "WAIS";
String strBuff = "";
int l =
strText.Length, pl = strPwd.Length;
if
(strPwd.Length > 0)
{
char[] s =
strText.ToCharArray();
char[] sp =
strPwd.ToCharArray();
l = s.Length;
for (i = 0; i
< l; i++)
{
n = (int)s[i];
n = n + sp[i % pl]; //Asc(Mid$(strPwd,
(i Mod Len(strPwd)) + 1, 1))
strBuff = strBuff + (char)(n & 0xFF);
}
}
else
strBuff = strText;
return strBuff;
}
internal string Encryptpwd(DataRow
dataRow)
{
throw new NotImplementedException();
}
}