public void EncryptString() { var sa = SymmetricFactory.CreateRijndael(); var key = new Key(Constants.PASSWORD); string test = sa.Decrypt(key, sa.Encrypt(key, Constants.TEST_STRING)); Assert.AreEqual(test, Constants.TEST_STRING); }
public void EncryptData() { var sa = SymmetricFactory.CreateRijndael(); var key = new Key(Constants.PASSWORD); var test = sa.Decrypt(key, sa.Encrypt(key, Constants.TEST_DATA)); Assert.IsTrue(Utilities.ValidateData(test)); }
public void EncryptStream() { using var src = new MemoryStream(Constants.TEST_DATA); using var enc = new MemoryStream(); using var dec = new MemoryStream(); var sa = SymmetricFactory.CreateRijndael(); var key = new Key(Constants.PASSWORD); sa.EncryptStream(key, src, enc); enc.Seek(0, SeekOrigin.Begin); sa.DecryptStream(key, enc, dec); var test = dec.ToArray(); Assert.IsTrue(Utilities.ValidateData(test)); }
public void EncryptFile() { string srcFile = Path.GetTempFileName(); string encFile = Path.GetTempFileName(); string decFile = Path.GetTempFileName(); var sa = SymmetricFactory.CreateRijndael(); var key = new Key(Constants.PASSWORD); try { File.WriteAllText(srcFile, Constants.TEST_STRING); sa.EncryptFile(key, srcFile, encFile); sa.DecryptFile(key, encFile, decFile); string test = File.ReadAllText(decFile); Assert.AreEqual(test, Constants.TEST_STRING); } finally { Utilities.Cleanup(srcFile, encFile, decFile); } }