HexHelper.cs 594 B

12345678910111213141516171819202122
  1. using System;
  2. using System.Globalization;
  3. namespace MediaBrowser.Common
  4. {
  5. public static class HexHelper
  6. {
  7. public static byte[] FromHexString(string str)
  8. {
  9. byte[] bytes = new byte[str.Length / 2];
  10. for (int i = 0; i < str.Length; i += 2)
  11. {
  12. bytes[i / 2] = byte.Parse(str.Substring(i, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
  13. }
  14. return bytes;
  15. }
  16. public static string ToHexString(byte[] bytes)
  17. => BitConverter.ToString(bytes).Replace("-", "");
  18. }
  19. }