The text of this article is not in this database — only its details are. Read it on the old site: Query String Encryption & Decryption Technique in ASP.Net 3.5
2 Comments
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.

bharath kumareditedPosted Feb 14, 2013, 1:36 AMEdited Feb 14, 2013, 1:37 AM
i have created a simple login page and want to Encrypt and Decrypt the password and the coads is not working correctly so plz see the error int the coading. coading: using System; using System.Collections; using System.Configuration; using System.Data; 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; using System.Security.Cryptography; using System.Data.SqlClient; namespace WebApplication5 { public partial class WebForm4 : System.Web.UI.Page { SqlConnection connection; protected void Page_Load(object sender, EventArgs e) { connection = new SqlConnection(ConfigurationManager.ConnectionStrings["TestQueryConnectionString"].ConnectionString); } protected void btnSubmit_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TestQueryConnectionString"].ConnectionString); string strpassword = EncodePasswordToBase64(txtPassword.Text); con.Open(); string strQuery = ("insert into admin( USERNAME,PASSWORD) values('" + txtUserName.Text + "','" + txtPassword.Text + "')"); connection = new SqlConnection(ConfigurationManager.ConnectionStrings["TestQueryConnectionString"].ConnectionString); connection.Open(); SqlCommand cmd = new SqlCommand(strQuery, connection); cmd.ExecuteNonQuery(); connection.Close(); SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["TestQueryConnectionString"].ConnectionString); string strpwd = EncodePasswordToBase64(txtPassword.Text); con1.Open(); SqlCommand cmd1 = new SqlCommand("select * from admin where USERNAME=@USERNAME and PASSWORD=@PASSWORD ", con); cmd1.Parameters.AddWithValue("@username", txtUserName.Text); cmd1.Parameters.AddWithValue("@password", txtPassword.Text); SqlDataAdapter da = new SqlDataAdapter(cmd1); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { Response.Redirect("emplist.aspx"); } else { ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>"); } con1.Close(); } public static string EncodePasswordToBase64(string password) { try { byte[] encData_byte = new byte[password.Length]; encData_byte = System.Text.Encoding.UTF8.GetBytes(password); string encodedData = Convert.ToBase64String(encData_byte); return encodedData; } catch (Exception ex) { throw new Exception("Error in base64Encode" + ex.Message); } } public string DecodeFrom64(string encodedData) { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(encodedData); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return result; } protected void btnClear_Click(object sender, EventArgs e) { txtUserName.Text = ""; txtPassword.Text = ""; } } }
manjusha nayakPosted Jun 11, 2012, 2:55 AM
Decryption not working for value 29.Is there any other solutions?