mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-21 21:33:01 +00:00
Moved PrivateKey to ApiCredentials, ApiCredentials use SecureString, Refactored array param string building
This commit is contained in:
@@ -1,27 +1,82 @@
|
||||
using System;
|
||||
using System.Security;
|
||||
|
||||
namespace CryptoExchange.Net.Authentication
|
||||
{
|
||||
public class ApiCredentials
|
||||
public class ApiCredentials: IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The api key
|
||||
/// The api key to authenticate requests
|
||||
/// </summary>
|
||||
public string Key { get; }
|
||||
public SecureString Key { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The api secret
|
||||
/// The api secret to authenticate requests
|
||||
/// </summary>
|
||||
public string Secret { get; }
|
||||
public SecureString Secret { get; }
|
||||
|
||||
public ApiCredentials() { }
|
||||
/// <summary>
|
||||
/// The private key to authenticate requests
|
||||
/// </summary>
|
||||
public SecureString PrivateKey { get; }
|
||||
|
||||
public ApiCredentials(string key, string secret)
|
||||
/// <summary>
|
||||
/// Create Api credentials providing a private key for authenication
|
||||
/// </summary>
|
||||
/// <param name="privateKey">The private key used for signing</param>
|
||||
public ApiCredentials(SecureString privateKey)
|
||||
{
|
||||
if(string.IsNullOrEmpty(key) || string.IsNullOrEmpty(secret))
|
||||
throw new ArgumentException("Apikey or apisecret not provided");
|
||||
PrivateKey = Key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create Api credentials providing a private key for authenication
|
||||
/// </summary>
|
||||
/// <param name="privateKey">The private key used for signing</param>
|
||||
public ApiCredentials(string privateKey)
|
||||
{
|
||||
var securePrivateKey = new SecureString();
|
||||
foreach (var c in privateKey)
|
||||
securePrivateKey.AppendChar(c);
|
||||
securePrivateKey.MakeReadOnly();
|
||||
PrivateKey = securePrivateKey;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create Api credentials providing a api key and secret for authenciation
|
||||
/// </summary>
|
||||
/// <param name="key">The api key used for identification</param>
|
||||
/// <param name="secret">The api secret used for signing</param>
|
||||
public ApiCredentials(SecureString key, SecureString secret)
|
||||
{
|
||||
Key = key;
|
||||
Secret = secret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create Api credentials providing a private key for authenication
|
||||
/// </summary>
|
||||
/// <param name="privateKey">The private key used for signing</param>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user