All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fisco.bcos.web3j.console.WalletCreator Maven / Gradle / Ivy

package org.fisco.bcos.web3j.console;

import java.io.File;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import org.fisco.bcos.web3j.crypto.CipherException;
import org.fisco.bcos.web3j.crypto.WalletUtils;
import org.fisco.bcos.web3j.utils.Console;

/** Simple class for creating a wallet file. */
public class WalletCreator extends WalletManager {

  public WalletCreator() {}

  public WalletCreator(IODevice console) {
    super(console);
  }

  public static void main(String[] args) {
    new WalletCreator().run();
  }

  static void main(IODevice console) {
    new WalletCreator(console).run();
  }

  private void run() {
    String password = getPassword("Please enter a wallet file password: ");
    String destinationDir = getDestinationDir();
    File destination = createDir(destinationDir);

    try {
      String walletFileName = WalletUtils.generateFullNewWalletFile(password, destination);
      console.printf(
          "Wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n");
    } catch (CipherException
        | IOException
        | InvalidAlgorithmParameterException
        | NoSuchAlgorithmException
        | NoSuchProviderException e) {
      Console.exitError(e);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy