1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-14 01:42:55 +00:00

Moved PrivateKey to ApiCredentials, ApiCredentials use SecureString, Refactored array param string building

This commit is contained in:
JKorf
2018-08-01 14:41:53 +02:00
parent b0cf1a899e
commit ed14082b9a
5 changed files with 107 additions and 60 deletions
+29 -1
View File
@@ -1,4 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
namespace CryptoExchange.Net
{
@@ -25,5 +28,30 @@ namespace CryptoExchange.Net
if (value != null)
parameters.Add(key, value);
}
public static string GetString(this SecureString source)
{
string result = null;
int length = source.Length;
IntPtr pointer = IntPtr.Zero;
char[] chars = new char[length];
try
{
pointer = Marshal.SecureStringToBSTR(source);
Marshal.Copy(pointer, chars, 0, length);
result = string.Join("", chars);
}
finally
{
if (pointer != IntPtr.Zero)
{
Marshal.ZeroFreeBSTR(pointer);
}
}
return result;
}
}
}