to encrypt use below code.
encryption and decryption
private const int prefix = 376;
private const string postfix = "P$Y";
public string encrypt(string _message)
{
string afterEncode;
byte[] b = ConvertToByte(_message);
int bl = b.Length;
afterEncode = Convert.ToBase64String(ConvertToByte(_message), 0, _message.Length);
//get length of encoded string and mask it by adding the prefix
int codeLengthint = afterEncode.Length + prefix;
//turn it back into a string, append the encoded word, and add a postfix to mask it
string codeLength = codeLengthint.ToString();
afterEncode = codeLength + afterEncode + postfix;
//encode again for good measure
afterEncode = Convert.ToBase64String(ConvertToByte(afterEncode));
//remove problematic characters and add a string that is unlikely to exist by chance
string testString = "";
string outString = "";
for (int i = 0; i < afterEncode.Length; i++)
{
testString = afterEncode[i].ToString();
if (testString == "?")
{
testString = "QUESTION";
}
else if (testString == "&")
{
testString = "AMPERSAND";
}
else if (testString == "=")
{
testString = "EQUALSTO";
}
outString += testString;
}
afterEncode = outString;
return afterEncode;
}
public string decrypt(string _message)
{
try
{
string afterEncode = _message;
string testString = "";
int codeLengthint = 0;
//replace key words with the characters they represent
while (afterEncode.IndexOf("QUESTION") != -1)
{
testString = afterEncode.Substring(0, afterEncode.IndexOf("QUESTION"));
afterEncode = testString + "?" + afterEncode.Substring(afterEncode.IndexOf("QUESTION") + 8);
}
while (afterEncode.IndexOf("AMPERSAND") != -1)
{
testString = afterEncode.Substring(0, afterEncode.IndexOf("AMPERSAND"));
afterEncode = testString + "&" + afterEncode.Substring(afterEncode.IndexOf("AMPERSAND") + 9);
}
while (afterEncode.IndexOf("EQUALSTO") != -1)
{
testString = afterEncode.Substring(0, afterEncode.IndexOf("EQUALSTO"));
afterEncode = testString + "=" + afterEncode.Substring(afterEncode.IndexOf("EQUALSTO") + 8);
}
afterEncode = ConvertToString(Convert.FromBase64String(afterEncode));
//get length of encoded character
codeLengthint = Convert.ToInt32(afterEncode.Substring(0, 3)) - prefix;
//retrieve encoded word and decrypt it
afterEncode = afterEncode.Substring(3, codeLengthint);
string afterDecode = ConvertToString(Convert.FromBase64String(afterEncode));
return afterDecode;
}
catch (Exception ex)
{
string sMsg = string.Format("SE2LegacyEncoding.Decode error - message = [{0}]", _message);
throw new Exception(sMsg, ex);
}
}
private byte[] ConvertToByte(string _string)
{
byte[] result = new byte[_string.Length];
// Convert each of the characters in the string to byte
for (int i = 0; i < _string.Length; i++) { result[i] = (byte)_string[i]; }
return result;
}
private string ConvertToString(byte[] _bytes)
{
char[] result = new char[_bytes.Length];
// Convert each of the characters in the string to byte
for (int i = 0; i < _bytes.Length; i++) { result[i] = (char)_bytes[i]; }
return new string(result);
}
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109:





by: AsishRajPosted on 2009-06-03 at 21:27:20ID: 24543568
its never ok to pass passwords without any encryptions. Store passwords as encrypted in DB
lla.com/ar ticles/103 002-1.aspx
have a look at this
http://www.4guysfromro