Using Encryption



MySqlBackup.NET provides internal encryption functionality.

Note: Encryption of v2.0 is not compatible with older version.

Example of Exporting with Encryption:

using (MySqlConnection conn = new MySqlConnection(connectionString))
{
    using (MySqlCommand cmd = new MySqlCommand())
    {
        using (MySqlBackup mb = new MySqlBackup(cmd))
        {
            cmd.Connection = conn;
            conn.Open();

            mb.ExportInfo.EnableEncryption = true;
            mb.ExportInfo.EncryptionPassword = "qwerty";
            mb.ExportToFile("C:\\backup.sql");
        }
    }
}

Example of Importing with Decryption:

using (MySqlConnection conn = new MySqlConnection(connectionString))
{
    using (MySqlCommand cmd = new MySqlCommand())
    {
        using (MySqlBackup mb = new MySqlBackup(cmd))
        {
            cmd.Connection = conn;
            conn.Open();

            mb.ImportInfo.EnableEncryption = true;
            mb.ImportInfo.EncryptionPassword = "qwerty";
            mb.ImportFromFile("C:\\backup.sql");
        }
    }
}

To Encrypt a Dump File:

using (MySqlBackup mb = new MySqlBackup())
{
    mb.EncryptDumpFile("C:\\backup.sql", "C:\\backup_encrypted.sql", "qwerty");
}

To Decrypt a Dump File:

using (MySqlBackup mb = new MySqlBackup())
{
    mb.DecryptDumpFile("C:\\backup_encrypted.sql", "C:\\backup.sql", "qwerty");
}

Last edited Dec 26, 2013 at 1:59 AM by adriancs, version 1