diff --git a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs
index 7a4112f..09aa93c 100644
--- a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs
+++ b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs
@@ -442,6 +442,14 @@ namespace CryptoExchange.Net.Authentication
///
///
protected static string BytesToHexString(byte[] buff)
+ => BytesToHexString(new ArraySegment(buff));
+
+ ///
+ /// Convert byte array to hex string
+ ///
+ ///
+ ///
+ protected static string BytesToHexString(ArraySegment buff)
{
#if NET9_0_OR_GREATER
return Convert.ToHexString(buff);
@@ -453,6 +461,26 @@ namespace CryptoExchange.Net.Authentication
#endif
}
+ ///
+ /// Convert a hex encoded string to byte array
+ ///
+ ///
+ ///
+ protected static byte[] HexToBytesString(string hexString)
+ {
+ if (hexString.StartsWith("0x"))
+ hexString = hexString.Substring(2);
+
+ byte[] bytes = new byte[hexString.Length / 2];
+ for (int i = 0; i < hexString.Length; i += 2)
+ {
+ string hexSubstring = hexString.Substring(i, 2);
+ bytes[i / 2] = Convert.ToByte(hexSubstring, 16);
+ }
+
+ return bytes;
+ }
+
///
/// Convert byte array to base64 string
///
diff --git a/CryptoExchange.Net/ExchangeHelpers.cs b/CryptoExchange.Net/ExchangeHelpers.cs
index 6e35421..dd4fbb0 100644
--- a/CryptoExchange.Net/ExchangeHelpers.cs
+++ b/CryptoExchange.Net/ExchangeHelpers.cs
@@ -242,8 +242,7 @@ namespace CryptoExchange.Net
///
/// Generate a long value
///
- /// Max character length
- ///
+ /// Max number of digits
public static long RandomLong(int maxLength)
{
#if NETSTANDARD2_1_OR_GREATER || NET9_0_OR_GREATER
@@ -259,6 +258,19 @@ namespace CryptoExchange.Net
return value;
}
+ public static long RandomLong(long minValue, long maxValue)
+ {
+#if NET8_0_OR_GREATER
+ var buf = RandomNumberGenerator.GetBytes(8);
+#else
+ byte[] buf = new byte[8];
+ var random = new Random();
+ random.NextBytes(buf);
+#endif
+ long longRand = BitConverter.ToInt64(buf, 0);
+ return (Math.Abs(longRand % (maxValue - minValue)) + minValue);
+ }
+
///
/// Generate a random string of specified length
///