Avatar ·

How to convert a byte array to a hexadecimal string and back in C#?

Hi everyone! I'm a beginner C# developer and I've run into a problem working with byte data. I need to save a hash (SHA256) to a text file, and then load it back for verification. I get the hash as a byte array (byte[]), but to write it to a file I need to convert it to a string, and then when reading it back — convert it back to a byte array. I tried simply using `BitConverter.ToString(bytes)`, but it returns a string with hyphens between bytes, for example: "A1-B2-C3". That's not exactly what I need — I'd like to get a compact string without separators, like "A1B2C3". And when I try to read such a string back, I don't know how to properly convert it to a byte array. Here's an example of my code that currently doesn't work as I'd like: ```csharp byte[] hashBytes = SHA