HexHelper.cs 626 B

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