Last post Aug 12, 2019 08:40 AM by PatriceSc
Jun 02, 2014 04:56 PM|harinis|LINK
I have the following code , my local machine gives different value than server . We have a process currently running on a server and we want to be able to deploy this to other servers and be able to get the same across servers.
static void Main(string args)
string imagePath = @"C:\Work\Projects\test.jpg";
System.Drawing.Image image = System.Drawing.Image.FromFile(imagePath);
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
imageBytes = ms.ToArray();
string photoCheckSumSha256 = ComputeSha256Checksum(imageBytes);
static string ComputeSha256Checksum(byte data)
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(data))
System.Security.Cryptography.SHA256 sha256 = new System.Security.Cryptography.SHA256CryptoServiceProvider();
byte sha256Ret = sha256.ComputeHash(stream);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < sha256Ret.Length; i++)
Jun 02, 2014 05:10 PM|markfitzme|LINK
Try setting a specific salt for all of them. Normally they shouldn't be the same as you don't want them the exact same each and every time. Think passwords. If you hash a password for one user, and another user changes the same password, they should be different
hashes. The reason is each has a different salt and that salt is saved along with the password. You will need to have the same salt for the same image across all instances that generate the hash or they won't match.
Jun 02, 2014 05:14 PM|harinis|LINK
We want to be able to detect if there are any duplicate images uploaded , this is not for security but to be able to check if the same image has been uploaded into the system already , and its not a real time check when the image is being loaded but for
Jun 02, 2014 07:30 PM|markfitzme|LINK
That's fine, but the entire principle of the SHA256 hash is the randomness of it. In this case, you can provide an identical seed in order to determine to all instances since security isn't an issue. That should cause an identical hash value to be generated
based on identical inputs. Providing an identical seed is a must if you want a hash value to be the same on each check.
Additionally, keep in mind that if even a pixel is off the hash may not match. If the sizes are adjusted then the images don't match.
For offline or non-realtime matchine you may want to look at: http://www.aforgenet.com/framework/features/template_matching.html This is a free .net libarary that can do exhaustive
image matchine. This is more flexible as it let's you define just how close two an image may be if you need to start matching close but non-exact matches (ie: if the image is scaled, saved with more compression, a filter, cropped, etc..)
Jun 02, 2014 09:52 PM|harinis|LINK
I have tested with a jpg file locally and deployed the same to server no changes, i still get a different hash value.
Aug 12, 2019 06:44 AM|shivam yadav|LINK
so how to decrypt hash to image
Aug 12, 2019 08:40 AM|PatriceSc|LINK
Done another response first as I missed you were hijacking an old discussion. It's likely best to open your own...
In short you can't. A hash function computes a quite short "thumbprint" value from a source input but you doesn't allow to retrieve the original value. For files it allows to download a file, do the same hash calculation and see if you get the same result
(which shows with a very high level of confidence that the file content was not altered).
See for example: www.differencebetween.info/difference-between-hashing-and-encryption
If you need further help I would suggest to open your own thread and explain what you are trying to do.