private static void Delete(SecureString key, int entryID) { using (WCFServiceClient client = new WCFServiceClient()) { bool result = client.Delete(entryID); if (result == true) { Console.WriteLine("Delete successful"); } } }
private static void Update(SecureString key, int entryID, string eventType, string user) { using (WCFServiceClient client = new WCFServiceClient()) { bool result = client.Update(entryID, string.Format(ResourceHelper.GetString(eventType), user)); if (result == true) { Console.WriteLine("Update successful"); } } }
private static SecureString GetKey() { SecureString key = new SecureString(); try { using (WCFServiceClient client = new WCFServiceClient()) { // Get client's certificate from the client credentials X509Certificate2 clientCertificate = SecurityHelper.GetCertificate(client); // Check in with the WCFService to receive the private key byte[] encryptedKey = client.CheckIn(); // If the encrypted key is null or empty, the service denied the request if (encryptedKey != null && encryptedKey.Length > 0) { // Decrypt the encrypted key data string privateKey = RSAEncrypter.Decrypt(encryptedKey, clientCertificate); // Clear the encrypted key data for security reasons Array.Clear(encryptedKey, 0, encryptedKey.Length); // Convert the decrypted key into a secure string key = StringConverter.ToSecureString(privateKey); // Clear the unsecure key for security reasons privateKey = string.Empty; Console.WriteLine("Private key retrieved from the service"); } else { Console.WriteLine("Unable to retrieve the private key from the service"); } } } catch (Exception e) { Console.WriteLine("[ERROR] {0}", e.Message); } return(key); }
private static void ReadFile(SecureString key) { using (WCFServiceClient client = new WCFServiceClient()) { byte[] encryptedFile = client.ReadFile(); if (encryptedFile != null) { List <string> serializedEntries = new List <string>(); if (encryptedFile.Any()) { string decryptedFile = AESEncrypter.Decrypt(encryptedFile, StringConverter.ToBytes(key)); serializedEntries.AddRange(decryptedFile.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); } HashSet <EventEntry> entries = new HashSet <EventEntry>(); foreach (string serializedEntry in serializedEntries) { entries.Add(new EventEntry(serializedEntry)); } if (!entries.Any()) { Console.WriteLine("Entry list is empty"); } else { foreach (var entry in entries) { Console.WriteLine(entry.ToString()); } } } } }