/// <summary> /// Create a new wallet /// </summary> /// <param name="key"></param> /// <param name="secret"></param> /// <param name="url"></param> /// <param name="nonce"></param> public Wallet(string key = "", string secret = "", string url = "", int nonce = 1) { if (key != String.Empty && secret != String.Empty) { auth = new GeminiWallet { Key = key, Secret = secret, Url = url, Nonce = nonce }; OnChange?.Invoke(this, null); } }
/// <summary> /// Create a new Wallet file, storing the API Key and Secret as AES-256 encrypted XML /// </summary> /// <param name="keys">GeminiWallet containing API key pair</param> /// <param name="filename">Filename for Wallet file</param> /// <param name="password">Password to use for AES-256 encryption</param> public void Create(GeminiWallet keys, string filename, string password) { using (var stream = new MemoryStream()) { XmlSerializer xml = new XmlSerializer(typeof(GeminiWallet)); xml.Serialize(stream, keys); stream.Seek(0, SeekOrigin.Begin); Cryptography.AesEncryption(stream, filename, password); _filename = filename; } }
/// <summary> /// Open an AES-256 encrypted Wallet file containing API Key and Secret /// </summary> /// <param name="filename"></param> /// <param name="password"></param> public void Open(string filename, string password) { Close(); Stream file = Cryptography.AesDecryption(filename, password); XmlSerializer xml = new XmlSerializer(typeof(GeminiWallet)); auth = xml.Deserialize(file) as GeminiWallet; file.Close(); _filename = filename; _password = password; OnChange?.Invoke(this, null); }
/// <summary> /// Save the currently loaded API Key and Secret to their original file /// </summary> public void Close() { if (auth == null) { return; } using (var s = new MemoryStream()) { XmlSerializer xml = new XmlSerializer(typeof(GeminiWallet)); xml.Serialize(s, auth); s.Seek(0, SeekOrigin.Begin); Cryptography.AesEncryption(s, _filename, _password); auth = null; } }