AesCryptFromStreamExample is an assembly/ library to serialize and encrypt data structures from C# as XML string to a file using AESCrypt.
private void Test()
{
var dbConnections = new List<DbConnection>
{
new DbConnection
{
ConnectionString = "cloud.asdf.org:user:password",
Name = "ASDF cloud"
},
new DbConnection
{
ConnectionString = "cloud.asdf2.org:user:password",
Name = "ASDF cloud2"
}
};
using (var aesCryptor = new AesCryptor())
{
aesCryptor.EncryptDbConnectionsToFile("Test.txt", dbConnections, "TestPW");
//File Test.txt.aes created with the encrypted data types
var dbConnectionsLoaded = aesCryptor.DecryptFileToDbConnection("Test.txt", "TestPW");
//dbConnectionsLoaded contains the stored data types in the file
}
}
This example only works with the AESCrypt library from NuGet.
You can easily customize the services when changing the DbConnection class, the XmlRootAttribute("DbConnections")
in the AESCryptor class and the DbConnections class (Especially the [XmlRoot("DbConnections")]
) to anything else
(Maybe even a generic way with T
parameter is possible).
See the Changelog.