本文整理了Java中org.web3j.crypto.Hash
类的一些代码示例,展示了Hash
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hash
类的具体详情如下:
包路径:org.web3j.crypto.Hash
类名称:Hash
[英]Cryptographic hash functions.
[中]加密散列函数。
代码示例来源:origin: web3j/web3j
/**
* Keccak-256 hash function.
*
* @param input binary encoded input data
* @return hash value
*/
public static byte[] sha3(byte[] input) {
return sha3(input, 0, input.length);
}
代码示例来源: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
/**
* Checksum address encoding as per
* <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md">EIP-55</a>.
*
* @param address a valid hex encoded address
* @return hex encoded checksum address
*/
public static String toChecksumAddress(String address) {
String lowercaseAddress = Numeric.cleanHexPrefix(address).toLowerCase();
String addressHash = Numeric.cleanHexPrefix(Hash.sha3String(lowercaseAddress));
StringBuilder result = new StringBuilder(lowercaseAddress.length() + 2);
result.append("0x");
for (int i = 0; i < lowercaseAddress.length(); i++) {
if (Integer.parseInt(String.valueOf(addressHash.charAt(i)), 16) >= 8) {
result.append(String.valueOf(lowercaseAddress.charAt(i)).toUpperCase());
} else {
result.append(lowercaseAddress.charAt(i));
}
}
return result.toString();
}
代码示例来源:origin: web3j/web3j
public static Bip32ECKeyPair generateKeyPair(byte[] seed) {
byte[] i = hmacSha512("Bitcoin seed".getBytes(), seed);
byte[] il = Arrays.copyOfRange(i, 0, 32);
byte[] ir = Arrays.copyOfRange(i, 32, 64);
Arrays.fill(i, (byte) 0);
Bip32ECKeyPair keypair = Bip32ECKeyPair.create(il, ir);
Arrays.fill(il, (byte) 0);
Arrays.fill(ir, (byte) 0);
return keypair;
}
代码示例来源:origin: web3j/web3j
private byte[] getIdentifier() {
return sha256hash160(getPublicKeyPoint().getEncoded(true));
}
代码示例来源:origin: web3j/web3j
data.put(parentPublicKey);
data.putInt(childNumber);
byte[] i = hmacSha512(getChainCode(), data.array());
byte[] il = Arrays.copyOfRange(i, 0, 32);
byte[] chainCode = Arrays.copyOfRange(i, 32, 64);
byte[] i = hmacSha512(getChainCode(), data.array());
byte[] il = Arrays.copyOfRange(i, 0, 32);
byte[] chainCode = Arrays.copyOfRange(i, 32, 64);
代码示例来源:origin: org.web3j/crypto
private byte[] getIdentifier() {
return sha256hash160(getPublicKeyPoint().getEncoded(true));
}
代码示例来源:origin: web3j/web3j
public static byte[] getAddress(byte[] publicKey) {
byte[] hash = Hash.sha3(publicKey);
return Arrays.copyOfRange(hash, hash.length - 20, hash.length); // right most 160 bits
}
代码示例来源:origin: web3j/web3j
private static byte[] hashTwice(byte[] input) {
return sha256(sha256(input));
}
代码示例来源:origin: web3j/web3j
@Test
public void testSha3String() {
assertThat(Hash.sha3String(""),
is("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
assertThat(Hash.sha3String("EVWithdraw(address,uint256,bytes32)"),
is("0x953d0c27f84a9649b0e121099ffa9aeb7ed83e65eaed41d3627f895790c72d41"));
}
代码示例来源:origin: org.web3j/crypto
public static Bip32ECKeyPair generateKeyPair(byte[] seed) {
byte[] i = hmacSha512("Bitcoin seed".getBytes(), seed);
byte[] il = Arrays.copyOfRange(i, 0, 32);
byte[] ir = Arrays.copyOfRange(i, 32, 64);
Arrays.fill(i, (byte) 0);
Bip32ECKeyPair keypair = Bip32ECKeyPair.create(il, ir);
Arrays.fill(il, (byte) 0);
Arrays.fill(ir, (byte) 0);
return keypair;
}
代码示例来源:origin: web3j/web3j
private static byte[] generateMac(byte[] derivedKey, byte[] cipherText) {
byte[] result = new byte[16 + cipherText.length];
System.arraycopy(derivedKey, 16, result, 0, 16);
System.arraycopy(cipherText, 0, result, 16, cipherText.length);
return Hash.sha3(result);
}
代码示例来源: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: org.web3j/crypto
/**
* Checksum address encoding as per
* <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md">EIP-55</a>.
*
* @param address a valid hex encoded address
* @return hex encoded checksum address
*/
public static String toChecksumAddress(String address) {
String lowercaseAddress = Numeric.cleanHexPrefix(address).toLowerCase();
String addressHash = Numeric.cleanHexPrefix(Hash.sha3String(lowercaseAddress));
StringBuilder result = new StringBuilder(lowercaseAddress.length() + 2);
result.append("0x");
for (int i = 0; i < lowercaseAddress.length(); i++) {
if (Integer.parseInt(String.valueOf(addressHash.charAt(i)), 16) >= 8) {
result.append(String.valueOf(lowercaseAddress.charAt(i)).toUpperCase());
} else {
result.append(lowercaseAddress.charAt(i));
}
}
return result.toString();
}
代码示例来源:origin: org.web3j/crypto
data.put(parentPublicKey);
data.putInt(childNumber);
byte[] i = hmacSha512(getChainCode(), data.array());
byte[] il = Arrays.copyOfRange(i, 0, 32);
byte[] chainCode = Arrays.copyOfRange(i, 32, 64);
byte[] i = hmacSha512(getChainCode(), data.array());
byte[] il = Arrays.copyOfRange(i, 0, 32);
byte[] chainCode = Arrays.copyOfRange(i, 32, 64);
代码示例来源:origin: web3j/web3j
public static String buildEventSignature(String methodSignature) {
byte[] input = methodSignature.getBytes();
byte[] hash = Hash.sha3(input);
return Numeric.toHexString(hash);
}
}
代码示例来源: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: eclipse/winery
contract.getContractAddress()).
addSingleTopic(EventEncoder.encode(event)).
addOptionalTopics(Hash.sha3String(identifier)).
addNullTopic();
final CompletableFuture<List<ModelProvenanceElement>> result = new CompletableFuture<>();
代码示例来源:origin: web3j/web3j
/**
* Keccak-256 hash function that operates on a UTF-8 encoded String.
*
* @param utf8String UTF-8 encoded string
* @return hash value as hex encoded string
*/
public static String sha3String(String utf8String) {
return Numeric.toHexString(sha3(utf8String.getBytes(StandardCharsets.UTF_8)));
}
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!