A basic way of doing it would be:
- Read the CSV File
- Sum the values
- Pass the
ToString
value to SHA-1
public static string GetSha1Sum()
{
double sum = 0;
using (CSVReader cr = new CSVReader(myfilename))
{
foreach (string[] line in cr)
{
//assuming your field is the first:
sum += Convert.ToDouble(line[0]);
}
}
SHA1 sha1Hash= SHA1.Create();
byte[] data = sha1Hash.ComputeHash(Encoding.UTF8.GetBytes(sum.ToString()));
string digest = HexDigest(data);
}
The HexDigest
helper is a function that format a byte array into hex string:
public static string HexDigest(byte[] data)
{
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
//format the bytes in hexadecimal
sBuilder.Append(data[i].ToString("x2"));
}
return sBuilder.ToString();
}
More information about the CSVReader