-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
54 lines (50 loc) · 1.69 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using Microsoft.Data.SqlClient;
using System.Data;
namespace alwaysencrypted
{
class Program
{
static string connectionString = "";
static void Main(string[] args)
{
Console.Write("Enter a secret: ");
string secret = Console.ReadLine();
var conn = new SqlConnection(connectionString);
string SQL = "INSERT INTO dbo.Secret(SafeData,UnsafeData) Values (@secret1,@secret2);";
var cmdInsert = new SqlCommand(SQL, conn);
var p1 = cmdInsert.CreateParameter();
p1.ParameterName = "@secret1";
p1.DbType = DbType.AnsiString;
p1.Direction = ParameterDirection.Input;
p1.Value = secret;
p1.Size = 200;
cmdInsert.Parameters.Add(p1);
var p2 = cmdInsert.CreateParameter();
p2.ParameterName = "@secret2";
p2.DbType = DbType.AnsiString;
p2.Direction = ParameterDirection.Input;
p2.Value = secret;
p2.Size = 200;
cmdInsert.Parameters.Add(p2);
var SQL2 = "SELECT SafeData FROM dbo.Secret;";
var cmdSelect = new SqlCommand(SQL2, conn);
conn.Open();
try
{
cmdInsert.ExecuteNonQuery();
var rdr = cmdSelect.ExecuteReader();
Console.WriteLine("Here are your secrets for all to see: ");
while (rdr.Read())
{
Console.WriteLine(rdr["SafeData"]);
}
}
finally
{
conn.Close();
}
Console.WriteLine("Done");
}
}
}