有加密解密类
public class ShareRSA
    {
        //加密
        public static string EncrytString(string word)
        {
            StreamReader sr = new StreamReader(@"f:\\publickey.txt", UTF8Encoding.UTF8);
            string readpublickey = sr.ReadToEnd();
            sr.Close();            RSACryptoServiceProvider crypt = new RSACryptoServiceProvider();
            UTF8Encoding enc = new UTF8Encoding();
            byte[] bytes = enc.GetBytes(word);
            crypt.FromXmlString(readpublickey);
            bytes = crypt.Encrypt(bytes, false);
            string encryttext = Convert.ToBase64String(bytes);
            string abb = Server.UrlEncode(encryttext);
           // Response.Write(abb);            return abb;
        }
        //解密:    
        public static string DecryptString(string word)
        {
            StreamReader sr = new StreamReader(@"f:\\privatekey.txt", UTF8Encoding.UTF8);
            string readprivatekey = sr.ReadToEnd();
            sr.Close();            //Response.Write("<br>" + word);            RSACryptoServiceProvider crypt = new RSACryptoServiceProvider();
            UTF8Encoding enc = new UTF8Encoding();
            byte[] bytes = Convert.FromBase64String(@word);
            crypt.FromXmlString(readprivatekey);
            byte[] decryptbyte = crypt.Decrypt(bytes, false);
            string decrypttext = enc.GetString(decryptbyte);            return decrypttext;
        }
        public static void CreateKey()
        {
            //公匙在a.txt文件中,私匙在b.txt文件中.             //制造公匙和私匙的方法如下:             crypt = new RSACryptoServiceProvider();
            publickey = crypt.ToXmlString(false);//公匙 
            privatekey = crypt.ToXmlString(true);//私匙 
            crypt.Clear();            //写入文本文件中 
            StreamWriter one = new StreamWriter(@"f:\\publickey.txt", true, UTF8Encoding.UTF8);
            one.Write(publickey);
            StreamWriter two = new StreamWriter(@"f:\\privatekey.txt", true, UTF8Encoding.UTF8);
            two.Write(privatekey);
            one.Flush();
            two.Flush();
            one.Close();
            two.Close();
            //MessageBox.Show("成功保存公匙和密匙!");
        }
    }
数据表member的字段:MemID,MemName,Email,Mobile,Password,RegTime,RegType,MemType,StatusShareRSA.EncrytString(MemRow["Mobile"].ToString())
   ShareRSA.EncrytString(MemRow["Password"].ToString())现在 Email,Mobile,Password都是加密保存在数据库里,
Email,Mobile都是唯一的.
现在想通过查询Email或者Mobile,找出对应行数据,高手请给解题思路

解决方案 »

  1.   

    select * from tb where email =@email
    使用sqlparameter,加密数据后查询
      

  2.   

    加解密类也有了,Email和Password也加密存好了,那只需要一个SQL语句就能查出来了。或者我没看懂楼主在纠结什么?
      

  3.   

    不对,每次email或者Mobile加密后,得到的字符串都不一样,查询参数传进去,怎么对得上数据表里的
      

  4.   

    比如输入: 123456
    Encrypted 加密后: oOLoVvELBIr4chYH4Y1NAnNwbSgt4hWKMQf9aBSHIUI=
    比如输入: 123456
    Encrypted 加密后: zjZEQuohUyEYbR4PukdHohQxKmEvL2/1ySm05ycqIrU=
    比如输入:  123456
    Encrypted 加密后: zJ3anzCNh4LHkvjE3KkghEvfryRBGziclK2YrYLC+VA=