public void TestEncryptAndDecrypt() { string input = "Test"; AESEncrypter encrypter = GetAESEncrypter(); string encrypted = encrypter.Encrypt(input); string decrypted = encrypter.Decrypt(encrypted); Assert.AreEqual(input, decrypted); }
private static void WriteToFile(List <string> entries) { // Concatenate all serialized entries into a string ready for encrypting string serializedEntries = string.Join("|", entries); // Convert the secure key into a byte array byte[] privateKeyBytes = StringConverter.ToBytes(PrivateKey); // Encrypt the file using the key byte[] encryptedFile = AESEncrypter.Encrypt(serializedEntries, privateKeyBytes); // Clear the key byte array for security reasons Array.Clear(privateKeyBytes, 0, privateKeyBytes.Length); // Overwrite the existing file with the encryped and serialized entries lock (fileLock) { File.WriteAllBytes(path, encryptedFile); } }