I am taking the MD5 hash of an image file and I want to use the hash as a filename.
How do I convert the hash to a string that is valid filename?
EDIT: toString()
just gives "System.Byte[]"
You cannot reverse the MD5 function, so your only option is to generate a new password and send that to the user (preferably over some secure channel).
It is possible to create a file given a hash value. However, if you have a file and create a MD5 hash this process will not recreate that file but create a small file filled with gibberish.
The usual definition of "MD5 hash of a file" is that the hash is based on the file contents. The name can be freely changed.
In the eDiscovery process, they are usually used to spot exact duplicates of files, as two identical files will have the same MD5 hash values (and thus the same digital signature.) The values are based on the low-level, binary data of files and not directly on the textual content or metadata of the file.
How about this:
string filename = BitConverter.ToString(yourMD5ByteArray);
If you prefer a shorter filename without hyphens then you can just use:
string filename =
BitConverter.ToString(yourMD5ByteArray).Replace("-", string.Empty);
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