Convert charArray to byteArray

For your purposes encoding is unnecessary, although it may be more convienient.

You could do instead,

sha.ComputeHash(validator.SelectMany(BitConverter.GetBytes).ToArray());

validator.Select(c => (byte)c).ToArray()

Will also work. The "string" type supports "IEnumerable", so you can use LINQ directly with one.

The "Select" method allows you specify a lambda to customize your output. This replaces what you were trying to do with the "ToArray(c => (byte)c))".


Encoding.GetEncoding("UTF-8").GetBytes(chararray);

Tags:

C#

Linq