public static void FILEINFO_TEST() { PreKeyring.FileInfo_Update(new FileMetaData { FileName = "HJY", FilePath = "SCAU", Key = "19920625", PlainTextHash = "12345", CryptTextHash = "67890" }); FileMetaData fi = PreKeyring.FileInfo_Query("SCAU"); Console.WriteLine( fi.FileName + " " + fi.FilePath + " " + fi.Key + " " + fi.PlainTextHash + " " + fi.CryptTextHash); PreKeyring.FileInfo_Update(new FileMetaData { FileName = "HJY2", FilePath = "SCAU2", Key = "19920625", PlainTextHash = "12345", CryptTextHash = "67890" }); PreKeyring.FileInfo_Update(new FileMetaData { FileName = "HJY2", FilePath = "SCAU3", Key = "19920625", PlainTextHash = "12345", CryptTextHash = "67890" }); PreKeyring.FileInfo_Update(new FileMetaData { FileName = "DLC", FilePath = "SCAU", Key = "19920625", PlainTextHash = "12345", CryptTextHash = "67890" }); fi = PreKeyring.FileInfo_Query("HHHHH"); Console.WriteLine( (fi == null) ? "The File HHHHH is not exist!!" : fi.FileName + " " + fi.FilePath + " " + fi.Key + " " + fi.PlainTextHash + " " + fi.CryptTextHash); //PreKeyring.FileInfo_Delete( new String[]{"SCAU2","SCAU3"} ); fi = PreKeyring.FileInfo_Query("SCAU2"); Console.WriteLine( (fi == null) ? "The File SCAU2 is not exist!!" : fi.FileName + " " + fi.FilePath + " " + fi.Key + " " + fi.PlainTextHash + " " + fi.CryptTextHash); fi = PreKeyring.FileInfo_Query("SCAU3"); Console.WriteLine( (fi == null) ? "The File SCAU3 is not exist!!" : fi.FileName + " " + fi.FilePath + " " + fi.Key + " " + fi.PlainTextHash + " " + fi.CryptTextHash); PreKeyring.Close(); }
static void Main(string[] args) { FileMetaData fi = PreKeyring.FileInfo_Query(@"C:\Users\637\Documents\SecuruStik\Home\RestartExplorer.bat"); Console.WriteLine( (fi == null) ? "The File HHHHH is not exist!!" : fi.FileName + " " + fi.FilePath + " " + fi.Key + " " + fi.PlainTextHash + " " + fi.CryptTextHash); Console.ReadLine(); }
public static Boolean FileInfo_Update(FileMetaData fi) { lock ( conn ) { try { if (fi.Key == null) { return(false); } fi.FilePath = Path.GetFullPath(fi.FilePath); fi.Key = Base64String.StringToBase64String(fi.Key); if (PreKeyring.GetRowsCountOfFilePath(fi.FilePath) == 0) { FileInfo_Insert(fi); } else { String sql = string.Format(SQLStatement.FileInfo_Update, fi.FileName, fi.FilePath, fi.Key, fi.PlainTextHash, fi.CryptTextHash); if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = sql; if (cmd.ExecuteNonQuery() != 1) { return(false); } } } } catch (System.Exception) { log.ErrorFormat("Update {0}", fi.FilePath); } } return(true); }
public static FileMetaData FileInfo_Query(String filePath) { FileMetaData fi = null; lock ( conn ) { try { if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = string.Format(SQLStatement.FileInfo_Query, Path.GetFullPath(filePath)); SqliteDataReader reader = cmd.ExecuteReader(); Boolean canRead = reader.Read(); if (canRead == false) { return(null); } else { fi = new FileMetaData(); fi.FileName = reader.GetString(0); fi.FilePath = reader.GetString(1); fi.Key = Base64String.Base64StringToString(reader.GetString(2)); fi.PlainTextHash = reader.GetString(3); fi.CryptTextHash = reader.GetString(4); } } } catch (System.Exception) { log.ErrorFormat("FileInfo query {0}", filePath); return(null); } } return(fi); }
public Boolean DownloadSharingFile(Protocal.SharingInfo si) { String copyRef = si.Reference; String fileName = si.FileName; try { String dropboxPath = BaseExtension.FileStringHelper.GetNonConflictFileName( Path.Combine( DropBoxController.DropBox_DownloadFolder , fileName ) ); UserKey uk = PreKeyring.UserKey; PRE_KEY userKey = new PRE_KEY(); userKey.PK.PK1 = uk.PK1; userKey.PK.PK2 = uk.PK2; userKey.SK.X1 = uk.SK1; userKey.SK.X2 = uk.SK2; PRE_Cipher CKey = new PRE_Cipher(); CKey.E = si.CKey_E; CKey.F = si.CKey_F; CKey.U = si.CKey_U; CKey.W = si.CKey_W; String key = ProxyReEncryption.KeyDecrypt( userKey , CKey ); FileMetaData fi = new FileMetaData(); fi.FileName = fileName; fi.FilePath = this.dropBoxController.DropboxSecuruStikFolder2SecuruStikFolder( dropboxPath ); fi.Key = key; fi.PlainTextHash = ""; fi.CryptTextHash = ""; PreKeyring.FileInfo_Update( fi ); String dropboxRemotePath = this.dropBoxController.SecuruStikFolder2RemoteDropboxPath( fi.FilePath ); this.dropBoxController.CopyAsync( copyRef , dropboxRemotePath ); } catch ( System.Exception ex ) { log.ErrorFormat("DownloadSharingFile {0}", si.FileName, ex); PreKeyring.SharingFile_Delete( si.Reference ); return false; } return true; }
private static Boolean FileInfo_Insert( FileMetaData fi ) { lock ( conn ) { try { if ( conn.State == ConnectionState.Closed ) conn.Open(); using ( SqliteCommand cmd = new SqliteCommand() ) { cmd.Connection = PreKeyring.conn; cmd.CommandText = string.Format( SQLStatement.FileInfo_Insert , fi.FileName , Path.GetFullPath( fi.FilePath ) , fi.Key , fi.PlainTextHash , fi.CryptTextHash ); cmd.ExecuteNonQuery(); } } catch ( Exception ){ log.ErrorFormat("Inserting {0}", fi.FilePath); return false; } } return true; }
public static Boolean FileInfo_Update( FileMetaData fi ) { lock ( conn ) { try { if ( fi.Key == null ) return false; fi.FilePath = Path.GetFullPath( fi.FilePath ); fi.Key = Base64String.StringToBase64String( fi.Key ); if ( PreKeyring.GetRowsCountOfFilePath( fi.FilePath ) == 0 ) { FileInfo_Insert( fi ); } else { String sql = string.Format( SQLStatement.FileInfo_Update , fi.FileName , fi.FilePath , fi.Key , fi.PlainTextHash , fi.CryptTextHash ); if ( conn.State == ConnectionState.Closed ) conn.Open(); using ( SqliteCommand cmd = new SqliteCommand() ) { cmd.Connection = PreKeyring.conn; cmd.CommandText = sql; if ( cmd.ExecuteNonQuery() != 1 ) return false; } } } catch ( System.Exception ){ log.ErrorFormat("Update {0}", fi.FilePath); } } return true; }
public static FileMetaData FileInfo_Query( String filePath ) { FileMetaData fi = null; lock ( conn ) { try { if ( conn.State == ConnectionState.Closed ) conn.Open(); using ( SqliteCommand cmd = new SqliteCommand() ) { cmd.Connection = PreKeyring.conn; cmd.CommandText = string.Format( SQLStatement.FileInfo_Query , Path.GetFullPath( filePath ) ); SqliteDataReader reader = cmd.ExecuteReader(); Boolean canRead = reader.Read(); if ( canRead == false ) return null; else { fi = new FileMetaData(); fi.FileName = reader.GetString( 0 ); fi.FilePath = reader.GetString( 1 ); fi.Key = Base64String.Base64StringToString( reader.GetString( 2 ) ); fi.PlainTextHash = reader.GetString( 3 ); fi.CryptTextHash = reader.GetString( 4 ); } } } catch ( System.Exception ) { log.ErrorFormat("FileInfo query {0}", filePath); return null; } } return fi; }