// Encrypt and decrypt the value or password and save in database.
con.Open(); // connection open
byte[] encData_byte = new byte[b.Length]; // Encrypt the code and store in "b1" string variable
encData_byte = System.Text.Encoding.UTF8.GetBytes(b); // " b " is the value which you want to encrypt
string b1 = Convert.ToBase64String(encData_byte); // Encrypted result
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); // Encrypt the code and store in "b2" string
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(b1); // " b1 " is the value which you want to decrypt
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 b2= new String(decoded_char); // Decrypted result
string sq = "insert into testlogin values('" + a.ToString() + "','" + b.ToString() + "','" + b1.ToString() + "','" + b2.ToString() + "')";
SqlCommand cmd = new SqlCommand(sq, con);
cmd.ExecuteNonQuery(); // Execute the query

No comments:
Post a Comment