public void CryptoDataFile_EncryptedEntireFileTest() { string passphraseString = "My Passphrase"; CryptoString passphrase = new CryptoString(CryptoString.StringToSecureString(passphraseString)); CryptoCredentials credentials = new CryptoCredentials { Passphrase = passphrase, }; string dataFileName = "EncryptedFile.bin"; string fileContent = "My Test Content"; using (AutoDeleteFiles autoDeleteFile = new AutoDeleteFiles(dataFileName)) { // Save some data CryptoDataFile dataFile = new CryptoDataFile(dataFileName); byte[] content1 = Encoding.UTF8.GetBytes(fileContent); dataFile.Credentials = credentials; dataFile.EncryptFile = true; dataFile.Content = content1; dataFile.Save(); byte[] fileBytes1 = dataFile.SaveToBytes(); // Now load the data and compare CryptoDataFile dataLoader = new CryptoDataFile(dataFileName); dataLoader.Credentials = credentials; dataLoader.EncryptFile = true; dataLoader.Load(); dataLoader.LoadFromBytes(fileBytes1); byte[] content2 = dataLoader.Content; Assert.IsTrue(content1.SequenceEqual(content2)); Assert.IsTrue(dataFile.Content.SequenceEqual(dataLoader.Content)); } }
public void CryptoDataFile_SaveLoadFromBytesTest() { string dataFileName = "testFile.bin"; string fileContent = "My Test Content"; // Save some data CryptoDataFile dataFile = new CryptoDataFile(dataFileName); byte[] content1 = Encoding.UTF8.GetBytes(fileContent); dataFile.Content = content1; dataFile.Save(); byte[] fileBytes1 = dataFile.SaveToBytes(); // Now load the data and compare CryptoDataFile dataLoader = new CryptoDataFile(dataFileName); dataLoader.Load(); dataLoader.LoadFromBytes(fileBytes1); byte[] content2 = dataLoader.Content; Assert.IsTrue(content1.SequenceEqual(content2)); Assert.IsTrue(dataFile.Content.SequenceEqual(dataLoader.Content)); }