Should I encode the data before hashing it to avoid Invalid length for a Base-64 char array.
# my .cs :
Stream des = file.InputStream;
byte[] data = new byte[file.ContentLength];
des.Read(data, 0, file.ContentLength);
FileStream f = new FileStream(targetFileName, FileMode.Create, FileAccess.ReadWrite);
f.Write(data, 0, data.Length);
f.Flush();
f.Close();
///////////////////////////////////////////////////////////////////////////////////////////
var sha = new System.Security.Cryptography.SHA512Managed();
string hash2 = Convert.ToBase64String(sha.ComputeHash(data));
and if the answer is yes How to encode the byte array.
Note:
I use hashing to uniquely identify the uploaded files for any change.
That error happens when decoding base-64, since a valid base-64 string is always a multiple of 4 characters (sometimes with a few padding chars). No, you do not need to encode/pad the input to
ToBase64String. Rather, it sounds like you are losing some characters when you are transporting / storing it (are you perhaps passing it on a query-string, and having a+vs space issue?)