org.web3j.crypto.WalletUtils.loadCredentials()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(366)

本文整理了Java中org.web3j.crypto.WalletUtils.loadCredentials()方法的一些代码示例,展示了WalletUtils.loadCredentials()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WalletUtils.loadCredentials()方法的具体详情如下:
包路径:org.web3j.crypto.WalletUtils
类名称:WalletUtils
方法名:loadCredentials

WalletUtils.loadCredentials介绍

暂无

代码示例

代码示例来源:origin: web3j/web3j

public static Credentials loadCredentials(String password, String source)
    throws IOException, CipherException {
  return loadCredentials(password, new File(source));
}

代码示例来源:origin: web3j/web3j

private void testGeneratedNewWalletFile(String fileName) throws Exception {
  WalletUtils.loadCredentials(PASSWORD, new File(tempDir, fileName));
}

代码示例来源:origin: web3j/web3j

private Credentials loadWalletFile(File walletFile) {
    while (true) {
      char[] password = console.readPassword(
          "Please enter your existing wallet file password: ");
      String currentPassword = new String(password);
      try {
        return WalletUtils.loadCredentials(currentPassword, walletFile);
      } catch (CipherException e) {
        console.printf("Invalid password specified\n");
      } catch (IOException e) {
        exitError("Unable to load wallet file: " + walletFile + "\n" + e.getMessage());
      }
    }
  }
}

代码示例来源:origin: web3j/web3j

private void testGenerateWalletFile(String fileName) throws Exception {
  Credentials credentials = WalletUtils.loadCredentials(
      PASSWORD, new File(tempDir, fileName));
  assertThat(credentials, equalTo(CREDENTIALS));
}

代码示例来源:origin: web3j/web3j

@Test
public void testLoadCredentialsFromString() throws Exception {
  Credentials credentials = WalletUtils.loadCredentials(
      PASSWORD,
      WalletUtilsTest.class.getResource(
          "/keyfiles/"
          + "UTC--2016-11-03T05-55-06."
          + "340672473Z--ef678007d18427e6022059dbc264f27507cd1ffc").getFile());
  assertThat(credentials, equalTo(CREDENTIALS));
}

代码示例来源:origin: web3j/web3j

@Test
public void testLoadCredentialsFromFile() throws Exception {
  Credentials credentials = WalletUtils.loadCredentials(
      PASSWORD,
      new File(WalletUtilsTest.class.getResource(
          "/keyfiles/"
              + "UTC--2016-11-03T05-55-06."
              + "340672473Z--ef678007d18427e6022059dbc264f27507cd1ffc")
          .getFile()));
  assertThat(credentials, equalTo(CREDENTIALS));
}

代码示例来源:origin: web3j/web3j

@Ignore  // enable if users need to work with MyEtherWallet
@Test
public void testLoadCredentialsMyEtherWallet() throws Exception {
  Credentials credentials = WalletUtils.loadCredentials(
      PASSWORD,
      new File(WalletUtilsTest.class.getResource(
          "/keyfiles/"
          + "UTC--2016-11-03T07-47-45."
          + "988Z--4f9c1a1efaa7d81ba1cabf07f2c3a5ac5cf4f818").getFile()));
  assertThat(credentials, equalTo(
      Credentials.create(
          "6ca4203d715e693279d6cd9742ad2fb7a3f6f4abe27a64da92e0a70ae5d859c9")));
}

代码示例来源:origin: ICOnator/ICOnator-backend

public EthereumTestPaymentService(Web3j web3j, String walletPassword, String walletPath)
    throws IOException, CipherException {
  this.credentials = WalletUtils.loadCredentials(walletPassword, walletPath);
  this.web3j = web3j;
}

代码示例来源:origin: org.jbpm.contrib/ethereum-workitem

public EthereumAuth(String walletPassword,
          String walletFilePath) throws Exception {
  walletCredentials = WalletUtils.loadCredentials(walletPassword,
                          walletFilePath);
}

代码示例来源:origin: org.jbpm.contrib/ethereum-workitem

public EthereumAuth(String walletPassword,
          File wallet) throws Exception {
  walletCredentials = WalletUtils.loadCredentials(walletPassword,
                          wallet);
}

代码示例来源:origin: ZainMustafaaa/Web3j-Android-Ether-Wallet-Ethereum-Client

/**
 * loadCredentials function is used to load the UTC-JSON file from a particular path.
 * @param password  is used to access your UTC-JSON file.
 * @throws IOException
 * @throws CipherException
 */
public static void loadCredentials(String password) throws IOException, CipherException {
  credentials = WalletUtils.loadCredentials(password, Environment.getExternalStorageDirectory().getAbsolutePath() + "/UTC--2017-08-21T11-49-30.013Z--8c17ea160c092ae854f81580396ba570d9e62e24.json");
}

代码示例来源:origin: matthiaszimmermann/ethereum-paper-wallet

public PaperWallet(String passPhrase, File walletFile) {
  // check if provided file exists
  if(!walletFile.exists() || walletFile.isDirectory()) { 
    System.err.println(String.format("%s file does not exist or is a directory", WALLET_ERROR));
  }
  
  try {
    credentials = WalletUtils.loadCredentials(passPhrase, walletFile);
  } 
  catch (Exception e) {
    System.err.println(String.format("%s failed to load credentials with provided password", WALLET_ERROR));
  }
}

代码示例来源:origin: eclipse/winery

private void unlockCredentials(String password, String fileSource) throws EthereumException {
  try {
    
    this.credentials = WalletUtils.loadCredentials(password, fileSource);
  } catch (IOException | CipherException e) {
    final String msg = "Error occurred while setting the user credentials for Ethereum. Reason: " +
      e.getMessage();
    log.error(msg);
    throw new EthereumException(msg, e);
  }
}

代码示例来源:origin: org.jbpm.contrib/ethereum-workitem

public EthereumAuth(String walletPassword,
          String walletFileName,
          ClassLoader classLoader) throws Exception {
  walletCredentials = WalletUtils.loadCredentials(walletPassword,
                          EthereumUtils.createTmpFile(classLoader.getResourceAsStream(walletFileName)));
}

代码示例来源:origin: matthiaszimmermann/ethereum-paper-wallet

public Credentials getCredentials(String passPhrase) throws Exception {
  if (credentials != null) {
    return credentials;
  }
  try {
    String fileWithPath = getFile().getAbsolutePath();
    credentials = WalletUtils.loadCredentials(passPhrase, fileWithPath);
    return credentials;
  }
  catch (Exception e) {
    throw new Exception ("Failed to access credentials in file '" + getFile().getAbsolutePath() + "'", e);
  }
}

代码示例来源:origin: ethjava/web3j-sample

/**
 * 导出私钥
 *
 * @param keystorePath 账号的keystore路径
 * @param password     密码
 */
private static void exportPrivateKey(String keystorePath, String password) {
  try {
    Credentials credentials = WalletUtils.loadCredentials(
        password,
        keystorePath);
    BigInteger privateKey = credentials.getEcKeyPair().getPrivateKey();
    System.out.println(privateKey.toString(16));
  } catch (IOException | CipherException e) {
    e.printStackTrace();
  }
}

相关文章