@@ -69,7 +69,7 @@ public static bool Exists_PublicKey(string Value) {
6969
7070
7171
72- public void Generate ( ) {
72+ public void Generate ( int Width = 25 , int Height = 25 ) {
7373 if ( User . Exists ( this . Username ) ) {
7474 return ;
7575 }
@@ -79,7 +79,7 @@ public void Generate() {
7979 SQLiteConnection connection = new SQLiteConnection ( connectionString ) ;
8080 connection . Open ( ) ;
8181
82- string sqlCommand = "INSERT INTO Main (Username, PublicKey) VALUES ('" + this . Username + "', '" + this . Key . Public + "');" ;
82+ string sqlCommand = "INSERT INTO Main (Username, PublicKey, Width, Height ) VALUES ('" + this . Username + "', '" + this . Key . Public + "', '" + Width + "', '" + Height + "');" ;
8383 SQLiteCommand command = new SQLiteCommand ( sqlCommand , connection ) ;
8484
8585 command = new SQLiteCommand ( sqlCommand , connection ) ;
@@ -88,6 +88,7 @@ public void Generate() {
8888 connection . Close ( ) ;
8989 }
9090 public void Generate_Chat ( string Name ) {
91+
9192 string Name1Hex = Encode . ByteArrayToHexString ( Encoding . ASCII . GetBytes ( this . Username ) ) ;
9293 string Name2Hex = Encode . ByteArrayToHexString ( Encoding . ASCII . GetBytes ( Name ) ) ;
9394
@@ -106,38 +107,30 @@ public void Generate_Chat(string Name) {
106107 {
107108 writer . WriteLine (
108109 Name +
109- ":" + // SymmetricKey.Item1+
110- Encode . ByteArrayToHexString ( Encoding . ASCII . GetBytes (
111- this . Key . Encrypt ( SymmetricKey . Item1 , User . Read_User_PublicKey ( Name ) )
112- ) ) +
113- ":" + // SymmetricKey.Item2
114- Encode . ByteArrayToHexString ( Encoding . ASCII . GetBytes (
115- this . Key . Encrypt ( SymmetricKey . Item2 , User . Read_User_PublicKey ( Name ) )
116- ) )
110+ ":" +
111+ this . Key . Encrypt ( SymmetricKey . Item1 , User . Read_User_PublicKey ( Name ) ) +
112+ ":" +
113+ this . Key . Encrypt ( SymmetricKey . Item2 , User . Read_User_PublicKey ( Name ) )
117114 ) ;
118115
119116 // User.Read_User_PublicKey(this.Username);
120117
121118 writer . WriteLine (
122119 this . Username +
123- ":" + // SymmetricKey.Item1+
124- Encode . ByteArrayToHexString ( Encoding . ASCII . GetBytes (
125- this . Key . Encrypt ( SymmetricKey . Item1 , User . Read_User_PublicKey ( this . Username ) )
126- ) ) +
127- ":" + // SymmetricKey.Item2
128- Encode . ByteArrayToHexString ( Encoding . ASCII . GetBytes (
129- this . Key . Encrypt ( SymmetricKey . Item2 , User . Read_User_PublicKey ( this . Username ) )
130- ) )
120+ ":" +
121+ this . Key . Encrypt ( SymmetricKey . Item1 , User . Read_User_PublicKey ( Name ) ) +
122+ ":" +
123+ this . Key . Encrypt ( SymmetricKey . Item2 , User . Read_User_PublicKey ( Name ) )
131124 ) ;
132125
133126 // User.Read_User_PublicKey(Name);
134127 }
135128
136- using ( StreamWriter writer = new StreamWriter ( @"chats\Write.txt" ) )
137- {
138- writer . WriteLine ( SymmetricKey . Item1 ) ;
139- writer . WriteLine ( SymmetricKey . Item2 ) ;
140- }
129+ // using (StreamWriter writer = new StreamWriter(@"chats\Write.txt"))
130+ // {
131+ // writer.WriteLine(SymmetricKey.Item1);
132+ // writer.WriteLine(SymmetricKey.Item2);
133+ // }
141134 }
142135 public static void Generate_Database ( ) {
143136 while ( ! System . IO . File . Exists ( "UserList.db" ) )
@@ -146,7 +139,7 @@ public static void Generate_Database() {
146139 SQLiteConnection connection = new SQLiteConnection ( connectionString ) ;
147140 connection . Open ( ) ;
148141
149- string query = "CREATE TABLE Main (Username TEXT, PublicKey TEXT)" ;
142+ string query = "CREATE TABLE Main (Username TEXT, PublicKey TEXT, Width INTEGER, Height INTEGER )" ;
150143 SQLiteCommand command = new SQLiteCommand ( query , connection ) ;
151144 command . ExecuteNonQuery ( ) ;
152145 connection . Close ( ) ;
@@ -243,24 +236,26 @@ public Tuple<string, string> Read_Chat_SymmetricKey(string SelectedChat) {
243236
244237 iv = EncryptedMessages [ 0 ] . Split ( ':' ) [ 2 ] ;
245238
239+ // Console.WriteLine(EncryptedMessages[0]);
240+
246241 } else {
247242
248243 SymmetricKey = EncryptedMessages [ 1 ] . Split ( ':' ) [ 1 ] ;
249244
250245 iv = EncryptedMessages [ 1 ] . Split ( ':' ) [ 2 ] ;
251246
247+ // Console.WriteLine(EncryptedMessages[1]);
248+
252249 }
253250
254251
255252
256- byte [ ] encryptedData = Encode . HexStringToByteArray ( SymmetricKey ) ;
257- string encryptedDataString = Convert . ToBase64String ( encryptedData ) ;
258- string decryptedData = this . Key . Decrypt ( encryptedDataString , this . Key . Private ) ;
253+ string encryptedData = SymmetricKey ;
254+ string decryptedData = this . Key . Decrypt ( encryptedData , this . Key . Private ) ;
259255 SymmetricKey = decryptedData ;
260256
261- encryptedData = Encode . HexStringToByteArray ( iv ) ;
262- encryptedDataString = Convert . ToBase64String ( encryptedData ) ;
263- decryptedData = this . Key . Decrypt ( encryptedDataString , this . Key . Private ) ;
257+ encryptedData = iv ;
258+ decryptedData = this . Key . Decrypt ( encryptedData , this . Key . Private ) ;
264259 iv = decryptedData ;
265260
266261
@@ -278,11 +273,11 @@ public Tuple<string, string> Read_Chat_SymmetricKey(string SelectedChat) {
278273 // Console.WriteLine(SymmetricKey);
279274 // Console.WriteLine(iv);
280275
281- using ( StreamWriter writer = new StreamWriter ( @"chats\Read.txt" ) )
282- {
283- writer . WriteLine ( SymmetricKey ) ;
284- writer . WriteLine ( iv ) ;
285- }
276+ // using (StreamWriter writer = new StreamWriter(@"chats\Read.txt"))
277+ // {
278+ // writer.WriteLine(SymmetricKey);
279+ // writer.WriteLine(iv);
280+ // }
286281
287282 return new Tuple < string , string > ( SymmetricKey , iv ) ;
288283 }
@@ -312,7 +307,7 @@ public static string Read_User_PublicKey(string User) {
312307 //System.Threading.Thread.Sleep(5000);
313308 string TempString = rdr . GetString ( 0 ) ;
314309 rdr . Close ( ) ;
315- Console . WriteLine ( TempString ) ;
310+ // Console.WriteLine(TempString);
316311 // System.Threading.Thread.Sleep(5000);
317312 // System.Threading.Thread.Sleep(5000);
318313 // System.Threading.Thread.Sleep(5000);
@@ -387,6 +382,10 @@ public class Chats
387382 {
388383
389384 public static string [ ] [ ] All ( string folder ) {
385+ if ( ! Directory . Exists ( folder ) ) {
386+ Directory . CreateDirectory ( folder ) ;
387+ System . Threading . Thread . Sleep ( 100 ) ;
388+ }
390389 FileInfo [ ] files = new DirectoryInfo ( folder ) . GetFiles ( "*.txt" ) ;
391390
392391 string [ ] fileNames = new string [ files . Length ] ;
0 commit comments