2021-09-27 12:42:46 +00:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
namespace Wabbajack.Hashing.xxHash64;
|
|
|
|
|
|
|
|
public static class StringExtensions
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
public static string ToHex(this byte[] bytes)
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
var builder = new StringBuilder();
|
|
|
|
for (var i = 0; i < bytes.Length; i++) builder.Append(bytes[i].ToString("x2"));
|
|
|
|
return builder.ToString();
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public static byte[] FromHex(this string hex)
|
|
|
|
{
|
|
|
|
return Enumerable.Range(0, hex.Length)
|
|
|
|
.Where(x => x % 2 == 0)
|
|
|
|
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
|
|
|
|
.ToArray();
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public static string ToBase64(this byte[] data)
|
|
|
|
{
|
|
|
|
return Convert.ToBase64String(data);
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public static byte[] FromBase64(this string data)
|
|
|
|
{
|
|
|
|
return Convert.FromBase64String(data);
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|
|
|
|
}
|