org.bitcoinj.wallet.Wallet.checkPassword()方法的使用及代码示例

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

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

Wallet.checkPassword介绍

[英]Check whether the password can decrypt the first key in the wallet. This can be used to check the validity of an entered password.
[中]检查密码是否可以解密钱包中的第一个密钥。这可用于检查输入密码的有效性。

代码示例

代码示例来源:origin: HashEngineering/dashj

@Nullable
private static KeyParameter passwordToKey(boolean printError) {
  if (password == null) {
    if (printError)
      System.err.println("You must provide a password.");
    return null;
  }
  if (!wallet.checkPassword(password)) {
    if (printError)
      System.err.println("The password is incorrect.");
    return null;
  }
  return checkNotNull(wallet.getKeyCrypter()).deriveKey(password);
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void changePasswordTest() {
  Wallet encryptedWallet = new Wallet(PARAMS);
  encryptedWallet.encrypt(PASSWORD1);
  CharSequence newPassword = "My name is Tom";
  encryptedWallet.changeEncryptionPassword(PASSWORD1, newPassword);
  assertTrue(encryptedWallet.checkPassword(newPassword));
  assertFalse(encryptedWallet.checkPassword(WRONG_PASSWORD));
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void encryptionDecryptionAESBasic() throws Exception {
  Wallet encryptedWallet = new Wallet(PARAMS);
  encryptedWallet.encrypt(PASSWORD1);
  KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter();
  KeyParameter aesKey = keyCrypter.deriveKey(PASSWORD1);
  assertEquals(EncryptionType.ENCRYPTED_SCRYPT_AES, encryptedWallet.getEncryptionType());
  assertTrue(encryptedWallet.checkPassword(PASSWORD1));
  assertTrue(encryptedWallet.checkAESKey(aesKey));
  assertFalse(encryptedWallet.checkPassword(WRONG_PASSWORD));
  assertNotNull("The keyCrypter is missing but should not be", keyCrypter);
  encryptedWallet.decrypt(aesKey);
  // Wallet should now be unencrypted.
  assertNull("Wallet is not an unencrypted wallet", encryptedWallet.getKeyCrypter());
  try {
    encryptedWallet.checkPassword(PASSWORD1);
    fail();
  } catch (IllegalStateException e) {
  }
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void encryptionDecryptionPasswordBasic() throws Exception {
  Wallet encryptedWallet = new Wallet(PARAMS);
  encryptedWallet.encrypt(PASSWORD1);
  assertTrue(encryptedWallet.isEncrypted());
  encryptedWallet.decrypt(PASSWORD1);
  assertFalse(encryptedWallet.isEncrypted());
  // Wallet should now be unencrypted.
  assertNull("Wallet is not an unencrypted wallet", encryptedWallet.getKeyCrypter());
  try {
    encryptedWallet.checkPassword(PASSWORD1);
    fail();
  } catch (IllegalStateException e) {
  }
}

相关文章

微信公众号

最新文章

更多

Wallet类方法