diff --git a/CryptoExchange.Net/Authentication/ApiCredentials.cs b/CryptoExchange.Net/Authentication/ApiCredentials.cs
index 141ff6a..f312ae3 100644
--- a/CryptoExchange.Net/Authentication/ApiCredentials.cs
+++ b/CryptoExchange.Net/Authentication/ApiCredentials.cs
@@ -1,27 +1,82 @@
using System;
+using System.Security;
namespace CryptoExchange.Net.Authentication
{
- public class ApiCredentials
+ public class ApiCredentials: IDisposable
{
///
- /// The api key
+ /// The api key to authenticate requests
///
- public string Key { get; }
+ public SecureString Key { get; }
+
///
- /// The api secret
+ /// The api secret to authenticate requests
///
- public string Secret { get; }
+ public SecureString Secret { get; }
- public ApiCredentials() { }
+ ///
+ /// The private key to authenticate requests
+ ///
+ public SecureString PrivateKey { get; }
- public ApiCredentials(string key, string secret)
+ ///
+ /// Create Api credentials providing a private key for authenication
+ ///
+ /// The private key used for signing
+ public ApiCredentials(SecureString privateKey)
{
- if(string.IsNullOrEmpty(key) || string.IsNullOrEmpty(secret))
- throw new ArgumentException("Apikey or apisecret not provided");
+ PrivateKey = Key;
+ }
+ ///
+ /// Create Api credentials providing a private key for authenication
+ ///
+ /// The private key used for signing
+ public ApiCredentials(string privateKey)
+ {
+ var securePrivateKey = new SecureString();
+ foreach (var c in privateKey)
+ securePrivateKey.AppendChar(c);
+ securePrivateKey.MakeReadOnly();
+ PrivateKey = securePrivateKey;
+ }
+
+ ///
+ /// Create Api credentials providing a api key and secret for authenciation
+ ///
+ /// The api key used for identification
+ /// The api secret used for signing
+ public ApiCredentials(SecureString key, SecureString secret)
+ {
Key = key;
Secret = secret;
}
+
+ ///
+ /// Create Api credentials providing a private key for authenication
+ ///
+ /// The private key used for signing
+ public ApiCredentials(string key, string secret)
+ {
+ var secureApiKey = new SecureString();
+ foreach (var c in key)
+ secureApiKey.AppendChar(c);
+ secureApiKey.MakeReadOnly();
+ Key = secureApiKey;
+
+ var secureApiSecret = new SecureString();
+ foreach (var c in secret)
+ secureApiSecret.AppendChar(c);
+ secureApiSecret.MakeReadOnly();
+ Secret = secureApiSecret;
+ }
+
+ public void Dispose()
+ {
+ Key?.Dispose();
+ Secret?.Dispose();
+ PrivateKey?.Dispose();
+ }
}
}
diff --git a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs
index 0dc3cd4..4dd1431 100644
--- a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs
+++ b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs
@@ -1,5 +1,4 @@
using CryptoExchange.Net.Interfaces;
-using System.Security;
namespace CryptoExchange.Net.Authentication
{
@@ -7,18 +6,11 @@ namespace CryptoExchange.Net.Authentication
{
public ApiCredentials Credentials { get; }
- public SecureString PrivateKey { get; }
-
protected AuthenticationProvider(ApiCredentials credentials)
{
Credentials = credentials;
}
- protected AuthenticationProvider(SecureString privateKey)
- {
- PrivateKey = privateKey;
- }
-
public virtual string AddAuthenticationToUriString(string uri, bool signed)
{
return uri;
diff --git a/CryptoExchange.Net/ExchangeClient.cs b/CryptoExchange.Net/ExchangeClient.cs
index 0606bff..6bf89cd 100644
--- a/CryptoExchange.Net/ExchangeClient.cs
+++ b/CryptoExchange.Net/ExchangeClient.cs
@@ -106,23 +106,12 @@ namespace CryptoExchange.Net
string paramString = null;
if (parameters != null)
{
- paramString = "with parameters ";
- int paramCount = 1;
+ paramString = "with parameters";
+
foreach (var param in parameters)
- {
- string paramValue = param.Value.ToString();
- if (param.Value.GetType().IsArray)
- paramValue = string.Format("[{0}]", string.Join(", ", ((object[])param.Value).Select(p => p.ToString())));
+ paramString += $" {param.Key}={(param.Value.GetType().IsArray ? $"[{string.Join(", ", ((object[])param.Value).Select(p => p.ToString()))}]": param.Value )},";
- paramString += $"{param.Key}={paramValue}";
-
- if (paramCount < parameters.Count)
- paramString += ", ";
- else
- paramString += ".";
-
- paramCount++;
- }
+ paramString = paramString.Trim(',');
}
log.Write(LogVerbosity.Debug, $"Sending {(signed ? "signed" : "")} request to {request.Uri} {(paramString ?? "")}");
@@ -140,25 +129,13 @@ namespace CryptoExchange.Net
uriString += "?";
var arraysParameters = parameters.Where(p => p.Value.GetType().IsArray).ToList();
- if (arraysParameters != null && arraysParameters.Count() > 0)
+ foreach(var arrayEntry in arraysParameters)
{
- bool isFirstEntry = true;
- arraysParameters.ForEach((arrayEntry) =>
- {
- if (!isFirstEntry)
- uriString += "&";
-
- List