Exemple #1
0
        public TextDetails GetData(int id)
        {
            SqlConnection cnn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Encrypt_DecryptDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            SqlCommand    cmd = new SqlCommand();

            cmd.Connection  = cnn;
            cmd.CommandText = "select * from textDetails where id=@id";
            SqlParameter p = new SqlParameter("@id", id);

            cmd.Parameters.Add(p);
            cnn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            TextDetails   td     = new TextDetails();

            if (reader.Read())
            {
                td.ID            = reader.GetInt32(0);
                td.Plaintext     = reader.GetString(1);
                td.Encryptedtext = reader.GetString(2);
                td.Decryptedtext = reader.GetString(3);
            }
            else
            {
                MyException m = new MyException();
                m.Reason = "No record found with given ID";
                throw new FaultException <MyException>(m);
            }
            reader.Close();
            cnn.Close();
            return(td);
        }
Exemple #2
0
        public TextDetails UpdateTextDetail(TextDetails td)
        {
            SqlConnection cnn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Encrypt_DecryptDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            SqlCommand    cmd = new SqlCommand();

            cmd.Connection  = cnn;
            cmd.CommandText = "update textDetails set plaintext=@plaintext,encryptedtext=@encryptedtext,decryptedtext=@decryptedtext where id=@id";

            SqlParameter para  = new SqlParameter("@id", td.ID);
            SqlParameter para1 = new SqlParameter("@plaintext", td.Plaintext);
            SqlParameter para2 = new SqlParameter("@encryptedtext", td.Encryptedtext);
            SqlParameter para3 = new SqlParameter("@decryptedtext", td.Decryptedtext);

            cmd.Parameters.Add(para);
            cmd.Parameters.Add(para1);
            cmd.Parameters.Add(para2);
            cmd.Parameters.Add(para3);

            cnn.Open();
            int reader = cmd.ExecuteNonQuery();

            cnn.Close();
            if (reader == 0)
            {
                MyException m = new MyException();
                m.Reason = "error! try again for updation";
                throw new FaultException <MyException>(m);
            }
            return(td);
        }
Exemple #3
0
        public bool AddData(TextDetails td)
        {
            SqlConnection cnn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Encrypt_DecryptDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            SqlCommand    cmd = new SqlCommand();

            cmd.Connection  = cnn;
            cmd.CommandText = "insert into textDetails(plaintext,encryptedtext,decryptedtext) values (@plaintext,@encryptedtext,@decryptedtext)";
            SqlParameter para  = new SqlParameter("@plaintext", td.Plaintext);
            SqlParameter para1 = new SqlParameter("@encryptedtext", td.Encryptedtext);
            SqlParameter para2 = new SqlParameter("@decryptedtext", td.Decryptedtext);

            cmd.Parameters.Add(para);
            cmd.Parameters.Add(para1);
            cmd.Parameters.Add(para2);

            cnn.Open();
            int reader = cmd.ExecuteNonQuery();

            cnn.Close();
            if (reader == 0)
            {
                return(false);
            }
            return(true);
        }