I have a string which under all circumstances satisfies ([a-zA-Z0-9])*
, and I want to let it run through sha1.
So how do I convert the string (or the char array obtained using ToCharArray()) to a byte array?
All answers I found so far have a big bunch of comments why the conversion from string to byte array is evil, they provide links to character encoding tutorials, and include a bunch of character encodings bloating the code.
Under my circumstances, conversion should be a LINQ oneliner, safe and neat.
I tried:
sha.ComputeHash(validator.ToCharArray().ToArray<byte>())
and I played around as far as my LINQ knowledge goes:
sha.ComputeHash(validator.ToCharArray().ToArray<byte>(c => (byte)c))