I want to Decrypt the Mysql Incrypted dump file with mysqlbackup.dll. I use bc.DecryptDumpFile() but this show error "Incorrect password or corrupted context" How to decrypt this file
MySqlBackup bc = new MySqlBackup();
bc.DecryptDumpFile(Application.StartupPath + "//POS_Assistant - 24-Jul-19.dll", Application.StartupPath + "//POS.sql", "Rehman92");
Maybe the below code helps:
private void DecryptDumpFile()
{
string oldDumpFile = "C:\\backup.sql";
string newDumpFile = "C:\\backup_new.sql";
MySqlBackup mb = new MySqlBackup();
mb.EnableEncryption = true;
mb.EncryptionKey = "qwerty";
mb.DecryptSqlDumpFile(oldDumpFile, newDumpFile);
}
Related
I've had a look around around SO and found some useful info on using a hash, but not actually any information on how to use it with the StreamWriter function in C#.
The code I used from SO was the code I found here: How to hash a password - Christian Gollhardt
CODE
private void Accept_Click(object sender, EventArgs e)
{
usrpass = usrpassTextbox.Text.ToString();
usrid = usridTextbox.Text.ToString();
if (FileExists() == true)
{
if (DialogResult.OK == MessageBox.Show("This user already exists, overwrite?", "Warning", MessageBoxButtons.OKCancel))
{
using (StreamWriter streamWriter = new StreamWriter(usrid + ".txt"))
{
streamWriter.WriteLine(usrpass);
MessageBox.Show(id + "'s password has been saved");
}
}
}
else
{
using (StreamWriter streamWriter = new StreamWriter(usrid + ".txt"))
streamWriter.WriteLine(usrpass);
MessageBox.Show(id + " " + "'s password has been saved");
}
}
}
Also I am considering putting the saving into a method to reduce code, I know there's no point in writing it out twice.
Desired Outcome
I would like the password that is being written to the .txt file to be hashed, if this is hashed, will the user still be able to login when I write a bit of code that checks if the user's txt file exists, then reads it for the password?
Will I have to unhash it?
As of yet, I have the code I borrowed from Christian but not sure how to use it to hash the usrpassbefore it is written to file
public static string CreateMD5(string input)
{
// Use input string to calculate MD5 hash
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);
// Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}
}
...
usrpass = CreateMD5(usrpassTextbox.Text.ToString());
I need to upload a CSV file to an ASP.NET application, on an Azure server. Although it works fine on my local machine, when uploading it to the server the following error is thrown:
"Process cannot access the file
'C:\inetpub\wwwroot\ImportFiles\9_11.csv' because it is being used by
another process"
My code:
string fileName = DateTime.Now.ToString().Replace(':', '_').Replace('/', '_').Replace(' ', '_') + Convert.ToString((new Random()).Next(0, 999) * (new Random()).Next(0, 999));
string path = Server.MapPath("ImportFiles") + "\\" + fileName + "" + FileImport.FileName.Substring(FileImport.FileName.IndexOf('.'));
FileImport.SaveAs(path);
string pathforSeconStream = path;
try
{
Response.Write("<script> alert('In Try Block');</script>");
bool flag = true;
int visiblemessageCount = 0;
int rollNo = 1;
StreamReader ColLine = new StreamReader(path);
string ColInputline = ColLine.ReadLine();
String[] ColsInput = ColInputline.Split(',');
ColLine.Close();
ColLine.Dispose();
string preFix = "", RollNumber = "";
StreamReader sr = new StreamReader(pathforSeconStream);
}
catch(Exception ex)
{
}
The code to generate a unique filename is wrong. Use Path.GetTempFileName.
PS never eat an exceptiion. Please remove catch (Exception ex) {};
Revision
Instead of FileImport.Save(...) just save the request in a MemoryStream and then work on it.
I've been trying to decrypt my file using GpgAPI in C#. It works fine, but it keeps prompting me for the password. The following code is what I used which is from the author's example.
public bool DecryptReport(string dataFileLocation, string filename)
{
log.Info("Starting GPG decryption.");
GpgInterface.ExePath = #"C:\Program Files (x86)\GNU\GnuPG\gpg2.exe";
String encryptedFile = dataFileLocation + filename;
filename = filename.ToString().Substring(0, filename.ToString().IndexOf(".gpg")).ToString();
string file = dataFileLocation + filename;
try
{
log.Info("Decrypting " + file);
GpgDecrypt decrypt = new GpgDecrypt(encryptedFile, file);
decrypt.AskPassphrase = GetPassword;
{
log.Info("Password received.");
GpgInterfaceResult result = decrypt.Execute();
Callback(result);
}
}
catch(Exception e)
{
log.Error("Caught an exception" + e.InnerException);
return false;
}
return true;
}
public static string Callback(GpgInterfaceResult result)
{
if(result.Status == GpgInterfaceStatus.Success)
{
return "successfully decrypted.";
}
else
{
return "Error was found during decryption. Check the log.";
}
}
public static SecureString GetPassword(AskPassphraseInfo arg)
{
return GpgInterface.GetSecureStringFromString(“password$");
}
What am I doing wrong in this code? Why does it not pass the password and continue decrypting instead of prompting for the password?
The gpg2 does not work as it should ... download the gpg classic.
Visit https://www.gnupg.org/download/ go to GnuPG binary -> Windows -> Simple installer for GnuPG classic.
Change GpgInterface.ExePath = #"C:\Program Files (x86)\GNU\GnuPG\gpg2.exe"; to "C:\Program Files (x86)\GNU\GnuPG\gpg.exe";
I have sfx files from the program that I created using sevenzipsharp library. still when I execute directly with double-click the file sfx if using the wrong password but still extract the files in it with a size of 0 bytes, if anyone should I add another mode to function 'Compress' so that when I execute the file sfx wrong password files are not extracted at all.
Compress code:
public void Compress()
{
SevenZipCompressor.SetLibraryPath("7z.dll");
SevenZipCompressor cmp = new SevenZipCompressor();
cmp.Compressing += new EventHandler<ProgressEventArgs>(cmp_Compressing);
cmp.FileCompressionStarted += new EventHandler<FileNameEventArgs>(cmp_StartCompress);
cmp.CompressionFinished += new EventHandler<EventArgs>(cmp_CompleteCompressed);
cmp.ArchiveFormat = OutArchiveFormat.SevenZip;
cmp.CompressionLevel = CompressionLevel.Normal;
cmp.CompressionMethod = CompressionMethod.Lzma;
cmp.CompressionMode = CompressionMode.Create;
string password = txtPasswordEn.Text;
string DirFile = tempFolder;
string NameFileCompress = Path.Combine(txtOutputFileEn.Text, txtNameFile.Text) + (".zip");
cmp.BeginCompressDirectory(DirFile, NameFileCompress, password, ".",true);
}
Create SFX Code:
public void CreateSfx()
{
string location = Path.Combine(txtOutputFileEn.Text, txtNameFile.Text);
string nameZip = location + (".zip");
string nameExe = location + (".exe");
SfxModule mdl = SfxModule.Extended;
SevenZipSfx sfx = new SevenZipSfx(mdl);
sfx.ModuleFileName = #"7z.sfx";
sfx.MakeSfx(nameZip, nameExe);
}
I've just seen that you're not creating a .zip file but a .7z file (and then convert it to a self extracting archive).
For that file format, you can achieve file name encryption using the EncryptHeaders property:
cmp.EncryptHeaders = true;
I need to retrieve an image from a database and save it to disk. In the database, the image is stored in binary format but datatype of the column is varchar(5000).
This is the code that I am using for retrieving the image and saving it to disk
public void CreateImageDataUsingDataReader_ForNetezzaDB()
{
string strDbConn = string.Empty;
string strImageFileName = string.Empty;
string strImageData = string.Empty;
string strImgSavePath = string.Empty;
string strQuery = string.Empty;
Byte[] byteImageData;
MemoryStream stmImageData = new MemoryStream();
Image saveImage;
try
{
//---open the database connection
strDbConn = ConfigurationSettings.AppSettings["NetezzaDBConnection"].ToString().Trim();
OleDbConnection dbcon = new OleDbConnection(strDbConn);
dbcon.Open();
strQuery = "select name,signature_vod__c from sfb_call2_vod where signature_vod__c is not null limit 10";
OleDbCommand cmdSelect = new OleDbCommand(strQuery, dbcon);
OleDbDataReader imageReader = cmdSelect.ExecuteReader();
if (imageReader.HasRows)
{
while (imageReader.Read())
{
strImageFileName = imageReader["name"].ToString().Trim();
strImageData = imageReader["signature_vod__c"].ToString().Trim();
stmImageData.Seek(0, SeekOrigin.Begin);
//converting string to byte array
byteImageData = Convert.FromBase64String(strImageData);
//---create Memory stremm from the Image Byte data
stmImageData.Write(byteImageData, 0, byteImageData.Length);
//--saving the image
//saveImage = Image.FromStream(stmImageData);
using (saveImage = Image.FromStream(stmImageData))
{
strImgSavePath = ConfigurationSettings.AppSettings["ImageSavePath"].ToString().Trim();
saveImage.Save(strImgSavePath + strImageFileName + ".png", System.Drawing.Imaging.ImageFormat.Png); ///---error comes in this line
}
}
}
imageReader.Close();
dbcon.Close();
stmImageData.Close();
stmImageData = null;
}
catch (Exception ex)
{
throw new Exception("Error Occured in method CreateImageDataUsingDataReader " + ex.Message);
}
}
but I keep getting an error:
A generic error occurred in GDI+.
Same code if I execute for SQL Server database it works fine but issue comes only with the Netezza database
Please help me resolve this issue
You mention that you store the binary image in a varchar column. This and the fact that it works on an other db technology makes it obious that you read different data back in the Netazza case.
I would suggest to setup a testproject where you persist the same image to the 2 different databases (netazza and mssql), read it back from both a do a bitwise comparison of the result either between the db results or between original and read from db.
I would be surprised if you get the same result and if I am right, you should probalaby consider to use a binary data type to persist the image data in your db backend.