How to recover image from hashcode?

oznawab

New member
Joined
Apr 11, 2011
Messages
3
Programming Experience
1-3
Hi Guys,

I have couple of hashcode values of image. So, how do I recover image from those?

Thanks in advance
 
You don't. Hashing is one-way. It is simply not possible to re-create the original data from a hash code.

Hashing is most generally used in one of two ways:

1. For security. For example, when a user registers, they provide a password and that password is hashed and stored in the database. That way, noone can ever get their password, even if they look in the database. When the user logs in, the application hashes the password they provide and compares the result to the value in the database. If they match, the user is authenticated.

2. For indexing. For example, a .NET Hashtable hashes its keys and uses them for fast retrieval of the values. When you specify a key, it is hashed and that value used to retrieve the corresponding value.

So, in your case, you might use the has codes to identify the images, but you still need to store the images themselves against those hashed keys.
 
Ok thanks but as I am new to this area, can you please tell if following string is a hashcode?

[FONT=&quot]FFF02F11A02F01902A01A02401E02002201C02701B02901A02D01D03202303402603402903303911403701603701803701A03701D03902303902503A02A03C02D03E02D04002A04102804402404602204802004A01F04C02104E02604E02A04D02C05412605402905402705502405502206111E06202206202406F11D06D01F06B02106A02306D02506F02707602807802807D02907F02907E02C07B02D07502F[/FONT]
 
There's no way to know for sure but I doubt it. Hash codes are usually shorter than that. That looks more like just a hexadecimal value. You could create such a value from an image like so:
VB.NET:
Using ms As New MemoryStream
    myImage.Save(ms, ImageFormat.Jpeg)

    Dim data = ms.GetBuffer()
    Dim builder As New stringbuilder

    For Each b In data
        builder.Append(b.ToString("X2"))
    Next

    MessageBox.Show(builder.ToString())
End Using
Note that you can create such a hexadecimal value from any Byte array, so it might be the image itself, the image data encrypted, the image data compressed, the image data encrypted and compressed, etc.
 
oh......!!!

now it makes sense, my bad!

so how do I create image from this hex string?

I am sorry if I am asking for too much.
 
You would use a For loop to process two characters of the String at a time. Byte.Parse can be used to convert each pair of characters to a number. Add the Bytes to a List as you go. When you're done, call ToArray on that List and create a MemoryStream using that Byte array. You can then call Image.FromStream to get an Image object.
 

Latest posts

Back
Top