public static Account LoadFromKeyStoreFile(string filePath, string password) { var keyStoreService = new Nethereum.KeyStore.KeyStoreService(); var key = keyStoreService.DecryptKeyStoreFromFile(password, filePath); return(new Account(key)); }
void LoadOrCreateAccount() { Nethereum.Signer.EthECKey key; var password = account_.password_; if (string.IsNullOrEmpty(keyStore_)) { if (encrypted_ && string.IsNullOrEmpty(password)) { Thread.MemoryBarrier(); result_ = -1; return; } key = CreateAccount(password, encrypted_, out keyStore_); } else { //generate ecKey from encrypted key store if (encrypted_) { var service = new Nethereum.KeyStore.KeyStoreService(); key = new Nethereum.Signer.EthECKey( service.DecryptKeyStoreFromJson(password, keyStore_), true); } else { key = new Nethereum.Signer.EthECKey(keyStore_); } } account_.key_ = key; Thread.MemoryBarrier(); result_ = 1; }
public Account LoadFromKeyStoreFile(string filePath, string password) { var keyStoreService = new Nethereum.KeyStore.KeyStoreService(); using (var file = File.OpenText(filePath)) { var json = file.ReadToEnd(); var key = keyStoreService.DecryptKeyStoreFromJson(password, json); return(new Account(key)); } }
private void LoadWalletFromKeystore(string keystoreJson, string password) { if (string.IsNullOrEmpty(keystoreJson) || string.IsNullOrEmpty(password)) { throw new System.InvalidOperationException("keystoreJson or password is null or empty"); } var keystoreservice = new Nethereum.KeyStore.KeyStoreService(); var privateKey = keystoreservice.DecryptKeyStoreFromJson(password, keystoreJson); var ecKey = new EthECKey(privateKey, true); var address = ecKey.GetPublicAddress(); PrivateKeyBytes = privateKey; PrivateKeyString = privateKey.ToHex(); PublicAddress = address; }
public void CreateAccount(string password) { var ecKey = Nethereum.Signer.EthECKey.GenerateKey(); var address = ecKey.GetPublicAddress(); var privateKey = ecKey.GetPrivateKeyAsBytes(); var keystoreservice = new Nethereum.KeyStore.KeyStoreService(); string encryptedJson = keystoreservice.EncryptAndGenerateDefaultKeyStoreAsJson(password, privateKey, address); File.WriteAllText(jsonPath, encryptedJson); this.password = password; this.publicAddress = address; this.privateKey = ecKey.GetPrivateKey(); this.encryptedJson = encryptedJson; }
public void LoadAccount() { var encryptedJson = PlayerPrefs.GetString("encryptedJson"); Debug.Log("encryptedJson " + encryptedJson); var password = "******"; var keystoreservice = new Nethereum.KeyStore.KeyStoreService(); var privateKey = keystoreservice.DecryptKeyStoreFromJson(password, encryptedJson); var ecKey = new EthECKey(privateKey, true); var address = ecKey.GetPublicAddress(); Debug.Log("address: " + address + "\n privateKey: " + privateKey.ToString()); accountAddress = address; accountPrivateKey = privateKey.ToHex(); Debug.Log("accountAddress: " + accountAddress + "\n accountPrivateKey: " + accountPrivateKey); }
// Code Comments for account creation and balance checks are available here: // https://gist.github.com/e11io/88f0ae5831f3aa31651f735278b5b463 // This function will just execute a callback after it creates and encrypt a new account public void CreateAccount(string password, System.Action <string, string> callback) { // We use the Nethereum.Signer to generate a new secret key var ecKey = Nethereum.Signer.EthECKey.GenerateKey(); var address = ecKey.GetPublicAddress(); var privateKey = ecKey.GetPrivateKeyAsBytes(); // Then we define a new KeyStore service var keystoreservice = new Nethereum.KeyStore.KeyStoreService(); // And we can proceed to define encryptedJson with EncryptAndGenerateDefaultKeyStoreAsJson(), // and send it the password, the private key and the address to be encrypted. var encryptedJson = keystoreservice.EncryptAndGenerateDefaultKeyStoreAsJson(password, privateKey, address); // Finally we execute the callback and return our public address and the encrypted json. // (you will only be able to decrypt the json with the password used to encrypt it) callback(address, encryptedJson); }
public void ImportAccountFromJson(string password, string encryptedJson) { try { var keystoreservice = new Nethereum.KeyStore.KeyStoreService(); var privateKey = keystoreservice.DecryptKeyStoreFromJson(password, encryptedJson); var address = keystoreservice.GetAddressFromKeyStore(encryptedJson); this.password = password; this.publicAddress = address; this.privateKey = ConvertKey(privateKey); this.encryptedJson = encryptedJson; } catch (DecryptionException ex) { Debug.Log("DecryptionException"); FindObjectOfType <AccountManager>().passwordNotice.enabled = true; return; } }
static Nethereum.Signer.EthECKey CreateAccount( string password, bool encryption, out string keyStore) { //Generate a private key pair using SecureRandom var key = Nethereum.Signer.EthECKey.GenerateKey(); //Create a store service, to encrypt and save the file using the web3 standard if (encryption) { var service = new Nethereum.KeyStore.KeyStoreService(); keyStore = service.EncryptAndGenerateDefaultKeyStoreAsJson( password, key.GetPrivateKeyAsBytes(), key.GetPublicAddress()); return(key); } else { keyStore = key.GetPrivateKey(); return(key); } }