Click here to Skip to main content
15,890,282 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to get a list og Outgoing MSMQ queues (without mention its knowing name) ? Pin
Luc Pattyn1-May-20 13:43
sitebuilderLuc Pattyn1-May-20 13:43 
GeneralRe: How to get a list og Outgoing MSMQ queues (without mention its knowing name) ? Pin
boozeeh12-May-20 1:31
boozeeh12-May-20 1:31 
QuestionUse DLL in C# Pin
Member 1481764029-Apr-20 15:16
Member 1481764029-Apr-20 15:16 
AnswerRe: Use DLL in C# Pin
Dave Kreskowiak29-Apr-20 16:56
mveDave Kreskowiak29-Apr-20 16:56 
AnswerRe: Use DLL in C# Pin
Luc Pattyn29-Apr-20 17:11
sitebuilderLuc Pattyn29-Apr-20 17:11 
AnswerRe: Use DLL in C# Pin
Eddy Vluggen30-Apr-20 9:34
professionalEddy Vluggen30-Apr-20 9:34 
AnswerRe: Use DLL in C# Pin
kalberts2-May-20 4:40
kalberts2-May-20 4:40 
QuestionCan not compare a file and same file stored in mysql - sha256 Pin
wilcodk29-Apr-20 7:40
wilcodk29-Apr-20 7:40 
I'm storing a file in a mysql table in a Longblob.

Now i would like to create a sha256 as a "footprint" for this file, so i can verify if the file exists already in my database.

As a test i've created this code

private byte[] ObjectToByteArray(Object obj)
{
    if (obj == null)
        return null;
    BinaryFormatter bf = new BinaryFormatter();
    MemoryStream ms = new MemoryStream();
    bf.Serialize(ms, obj);
    return ms.ToArray();
}

private void button5_Click(object sender, EventArgs e)
{
    byte[] bookData = null;
    byte[] bookDataSha = null;
    book bog = getBookById("6");
    bog.GetEbookHash(string.Format(@"H:\calibre\{0}\", bog.path), 6);

    using (var db = new MySqlConnection(@"server = xxxxxxx"))
    {
        MySql.Data.MySqlClient.MySqlDataReader myData;

        db.Open();
        MySqlCommand comm = db.CreateCommand();
        comm.CommandText = "select content from bookContent where id='6' and type='epub'";
        myData = comm.ExecuteReader();
        while (myData.Read())
        {
            bookData  = this.ObjectToByteArray(myData["content"]);
            bookDataSha = Sha256.ComputeHash(bookData);
        }
        db.Close();
    }

    if (bog.EpubHash == bookDataSha)
    {
        MessageBox.Show("success");
    }
    MessageBox.Show(bog.getEbookHashStr(bog.EpubHash)+" - "+bog.getEbookHashStr(bookDataSha));
}


My problem is that the 2 sha256's isnt equal.

I've found this Generate a SHA-256 encrypted hash[^]

and when i upload the file i test on, it creates the same sha256 as my code for the file does.
But when i read the data from the longblob and creates a sha256 it is different.
The strange part, is that if i use my website to download the same longblob and saves it as a file... FC cant find any diffeneces.

What do i do wrong ?

Thanks in advance
Yours

Wilco

AnswerRe: Can not compare a file and same file stored in mysql - sha256 Pin
Luc Pattyn29-Apr-20 8:07
sitebuilderLuc Pattyn29-Apr-20 8:07 
GeneralRe: Can not compare a file and same file stored in mysql - sha256 Pin
wilcodk30-Apr-20 1:32
wilcodk30-Apr-20 1:32 
AnswerRe: Can not compare a file and same file stored in mysql - sha256 Pin
Mycroft Holmes29-Apr-20 12:18
professionalMycroft Holmes29-Apr-20 12:18 
GeneralRe: Can not compare a file and same file stored in mysql - sha256 Pin
wilcodk30-Apr-20 1:28
wilcodk30-Apr-20 1:28 
AnswerRe: Can not compare a file and same file stored in mysql - sha256 Pin
Eddy Vluggen30-Apr-20 6:34
professionalEddy Vluggen30-Apr-20 6:34 
QuestionCompare string time to timer time (noobie) Pin
Member 1481029228-Apr-20 5:36
Member 1481029228-Apr-20 5:36 
AnswerRe: Compare string time to timer time (noobie) Pin
Gerry Schmitz28-Apr-20 6:48
mveGerry Schmitz28-Apr-20 6:48 
QuestionResize and move a drawn rectangle in win forms Pin
Member 1223285027-Apr-20 12:23
Member 1223285027-Apr-20 12:23 
AnswerRe: Resize and move a drawn rectangle in win forms Pin
Luc Pattyn27-Apr-20 13:17
sitebuilderLuc Pattyn27-Apr-20 13:17 
GeneralRe: Resize and move a drawn rectangle in win forms Pin
Member 1223285027-Apr-20 19:38
Member 1223285027-Apr-20 19:38 
GeneralRe: Resize and move a drawn rectangle in win forms Pin
Luc Pattyn28-Apr-20 4:50
sitebuilderLuc Pattyn28-Apr-20 4:50 
GeneralRe: Resize and move a drawn rectangle in win forms Pin
Member 1223285028-Apr-20 17:56
Member 1223285028-Apr-20 17:56 
GeneralRe: Resize and move a drawn rectangle in win forms Pin
Luc Pattyn29-Apr-20 2:30
sitebuilderLuc Pattyn29-Apr-20 2:30 
QuestionDate compare Pin
Carlos5827-Apr-20 10:42
Carlos5827-Apr-20 10:42 
AnswerRe: Date compare Pin
Luc Pattyn27-Apr-20 11:00
sitebuilderLuc Pattyn27-Apr-20 11:00 
GeneralRe: Date compare Pin
Carlos5827-Apr-20 12:31
Carlos5827-Apr-20 12:31 
GeneralRe: Date compare Pin
Luc Pattyn27-Apr-20 12:48
sitebuilderLuc Pattyn27-Apr-20 12:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.