Here is 2 simple functions for Password Encryption and Decryption.
using System.Security.Cryptography; private string EncryptedPassword(string ValueToEncrypt) { MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, cryptObj.CreateEncryptor(KEY_128, IV_128), CryptoStreamMode.Write); StreamWriter sw = new StreamWriter(cs); sw.Write(ValueToEncrypt); sw.Flush(); cs.FlushFinalBlock(); ms.Flush(); return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length); } private string DecryptedPassword(string ValueToDecrypt) { byte [] buf = Convert.FromBase64String(ValueToDecrypt); MemoryStream ms = new MemoryStream(buf); CryptoStream cs = new CryptoStream(ms, cryptObj.CreateDecryptor(KEY_128, IV_128), CryptoStreamMode.Read); StreamReader sr = new StreamReader(cs); return sr.ReadToEnd();
}
|
| Author: Shadab Hasn 05 Feb 2008 | Member Level: Bronze Points : 0 |
Hi i an geting error on the following line,
CryptoStream cs = new CryptoStream(ms, cryptObj.CreateEncryptor(KEY_128, IV_128), CryptoStreamMode.Write);
"The name 'cryptObj' does not exist in the current context D:\Cryptography\Default2.aspx.cs"
http://www.dotnetspider.com/code/C-539-Password-Encryption-Decryption-samples.aspx
Pls help me
|
| Author: santhoshkumar 28 Apr 2008 | Member Level: Gold Points : 2 |
Hi please try to explain this .. CryptoStream cs = new CryptoStream(ms, cryptObj.CreateEncryptor(KEY_128, IV_128), CryptoStreamMode.Write);
What is the meaning of this line and if "KEY_128,IV_128" it is a key then shalll we use some other key, please mention some other key with explation. please
|