Example #1
0
        private void SaveWallet(string path, string password)
        {
            var wallet = new JsonWallet
                         (
                EcdsaKeyPair.PrivateKey.ToHex(),
                HubPrivateKey.ToHex(),
                new Dictionary <ulong, string>(
                    _tpkeKeys.Select(p =>
                                     new System.Collections.Generic.KeyValuePair <ulong, string>(
                                         p.Key, p.Value.ToHex()
                                         )
                                     )
                    ),
                new Dictionary <ulong, string>(
                    _tsKeys.Select(p =>
                                   new System.Collections.Generic.KeyValuePair <ulong, string>(
                                       p.Key, p.Value.ToHex()
                                       )
                                   )
                    )
                         );
            var json             = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(wallet));
            var key              = Encoding.UTF8.GetBytes(password).KeccakBytes();
            var encryptedContent = Crypto.AesGcmEncrypt(key, json);

            File.WriteAllBytes(path, encryptedContent);
        }
Example #2
0
        private static void GenerateNewWallet(string path, string password)
        {
            var config = new JsonWallet(
                CryptoProvider.GetCrypto().GenerateRandomBytes(32).ToHex(false),
                GenerateHubKey().PrivateKey,
                new Dictionary <ulong, string> {
            },
                new Dictionary <ulong, string> {
            }
                );
            var json         = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(config));
            var passwordHash = Encoding.UTF8.GetBytes(password).KeccakBytes();
            var crypto       = CryptoProvider.GetCrypto();

            File.WriteAllBytes(path, crypto.AesGcmEncrypt(passwordHash, json));
        }