Need MD5 hash for an in memory System.Drawing.Image
Type the following command: md5sum [type file name with extension here] [path of the file] -- NOTE: You can also drag the file to the terminal window instead of typing the full path. Hit the Enter key. You'll see the MD5 sum of the file.
MD5 is a one-way hash algorithm as defined by RFC1321 and can be used to help determine the integrity of a file by providing a 128 bit digital signature. This digital signature is like a fingerprint for a file; changing just one single byte in a file will result in a different MD5 hash.
An MD5 hash is created by taking a string of an any length and encoding it into a 128-bit fingerprint. Encoding the same string using the MD5 algorithm will always result in the same 128-bit hash output.
A hash value does not appear on the face of a document or file but is part of the file's metadata. MD5 and SHA are common types of hash values. Documents with matching hash values are exact duplicates.
Here is a basic snippet. See also @JaredReisinger 's comment for some questions.
using System.Security.Cryptography;
using System.Text;
using System.Drawing.Imaging;
// ...
// get the bytes from the image
byte[] bytes = null;
using( MemoryStream ms = new MemoryStream() )
{
image.Save(ms,ImageFormat.Gif); // gif for example
bytes = ms.ToArray();
}
// hash the bytes
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] hash = md5.ComputeHash(bytes);
// make a hex string of the hash for display or whatever
StringBuilder sb = new StringBuilder();
foreach (byte b in hash)
{
sb.Append(b.ToString("x2").ToLower());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With