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

x33g5p2x  于2022-01-20 转载在 其他  
字(2.6k)|赞(0)|评价(0)|浏览(128)

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

Hash.sha256介绍

[英]Generates SHA-256 digest for the given input.
[中]为给定输入生成SHA-256摘要。

代码示例

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

public static byte calculateChecksum(byte[] initialEntropy) {
  int ent = initialEntropy.length * 8;
  byte mask = (byte) (0xff << 8 - ent / 32);
  byte[] bytes = sha256(initialEntropy);
  return (byte) (bytes[0] & mask);
}

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

private static byte[] hashTwice(byte[] input) {
  return sha256(sha256(input));
}

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

public static byte[] sha256hash160(byte[] input) {
    byte[] sha256 = sha256(input);
    RIPEMD160Digest digest = new RIPEMD160Digest();
    digest.update(sha256, 0, sha256.length);
    byte[] out = new byte[20];
    digest.doFinal(out, 0);
    return out;
  }
}

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

public static Credentials loadBip39Credentials(String password, String mnemonic) {
  byte[] seed = MnemonicUtils.generateSeed(mnemonic, password);
  return Credentials.create(ECKeyPair.create(sha256(seed)));
}

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

/**
 * Generates a BIP-39 compatible Ethereum wallet. The private key for the wallet can
 * be calculated using following algorithm:
 * <pre>
 *     Key = SHA-256(BIP_39_SEED(mnemonic, password))
 * </pre>
 *
 * @param password Will be used for both wallet encryption and passphrase for BIP-39 seed
 * @param destinationDirectory The directory containing the wallet
 * @return A BIP-39 compatible Ethereum wallet
 * @throws CipherException if the underlying cipher is not available
 * @throws IOException if the destination cannot be written to
 */
public static Bip39Wallet generateBip39Wallet(String password, File destinationDirectory)
    throws CipherException, IOException {
  byte[] initialEntropy = new byte[16];
  secureRandom.nextBytes(initialEntropy);
  String mnemonic = MnemonicUtils.generateMnemonic(initialEntropy);
  byte[] seed = MnemonicUtils.generateSeed(mnemonic, password);
  ECKeyPair privateKey = ECKeyPair.create(sha256(seed));
  String walletFile = generateWalletFile(password, privateKey, destinationDirectory, false);
  return new Bip39Wallet(walletFile, mnemonic);
}

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

@Test
public void testGenerateBip39Wallets() throws Exception {
  Bip39Wallet wallet = WalletUtils.generateBip39Wallet(PASSWORD, tempDir);
  byte[] seed = MnemonicUtils.generateSeed(wallet.getMnemonic(), PASSWORD);
  Credentials credentials = Credentials.create(ECKeyPair.create(sha256(seed)));
  assertEquals(credentials, WalletUtils.loadBip39Credentials(PASSWORD, wallet.getMnemonic()));
}

代码示例来源:origin: org.web3j/crypto

public static byte calculateChecksum(byte[] initialEntropy) {
  int ent = initialEntropy.length * 8;
  byte mask = (byte) (0xff << 8 - ent / 32);
  byte[] bytes = sha256(initialEntropy);
  return (byte) (bytes[0] & mask);
}

相关文章

微信公众号

最新文章

更多