org.spongycastle.util.encoders.Hex.toHexString()方法的使用及代码示例

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

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

Hex.toHexString介绍

暂无

代码示例

代码示例来源:origin: ethereum/ethereumj

public static String getHashListShort(List<byte[]> blockHashes) {
  if (blockHashes.isEmpty()) return "[]";
  StringBuilder sb = new StringBuilder();
  String firstHash = Hex.toHexString(blockHashes.get(0));
  String lastHash = Hex.toHexString(blockHashes.get(blockHashes.size() - 1));
  return sb.append(" ").append(firstHash).append("...").append(lastHash).toString();
}

代码示例来源:origin: ethereum/ethereumj

/**
 * @return generates random peer id for the HelloMessage
 */
public static byte[] randomPeerId() {
  byte[] peerIdBytes = new BigInteger(512, Utils.getRandom()).toByteArray();
  final String peerId;
  if (peerIdBytes.length > 64)
    peerId = Hex.toHexString(peerIdBytes, 1, 64);
  else
    peerId = Hex.toHexString(peerIdBytes);
  return Hex.decode(peerId);
}

代码示例来源:origin: ethereum/ethereumj

private String bytesToAscii(byte[] b) {
  String hex = Hex.toHexString(b);
  StringBuilder output = new StringBuilder();
  for (int i = 0; i < hex.length(); i += 2) {
    String str = hex.substring(i, i + 2);
    output.append((char) Integer.parseInt(str, 16));
  }
  return output.toString();
}

代码示例来源:origin: ethereum/ethereumj

@Override
  public ValidationResult validate(BlockHeader header) {
    if (!FastByteComparisons.equal(header.getHash(), blockHash)) {
      return fault("Block " + header.getNumber() + " hash constraint violated. Expected:" +
          Hex.toHexString(blockHash) + ", got: " + Hex.toHexString(header.getHash()));
    }
    return Success;
  }
}

代码示例来源:origin: ethereum/ethereumj

private Block loadGenesisFromFile(String resPath) {
  Block genesis = GenesisLoader.loadGenesis(getClass().getResourceAsStream(resPath));
  logger.info(genesis.toString());
  logger.info("genesis hash: [{}]", Hex.toHexString(genesis.getHash()));
  logger.info("genesis rlp: [{}]", Hex.toHexString(genesis.getEncoded()));
  return genesis;
}

代码示例来源:origin: ethereum/ethereumj

@Override
public String toString() {
  return "NodeHandler[state: " + state + ", node: " + node.getHost() + ":" + node.getPort() + ", id="
      + (node.getId().length >= 4 ? Hex.toHexString(node.getId(), 0, 4) : "empty") + "]";
}

代码示例来源:origin: ethereum/ethereumj

@Test
public void testRIPEMD160_Multiple() {
  String expected1 = "9295fac879006ff44812e43b83b515a06c2950aa";
  String result1 = Hex.toHexString(HashUtil.ripemd160("test1".getBytes()));
  assertEquals(expected1, result1);
  String expected2 = "80b85ebf641abccdd26e327c5782353137a0a0af";
  String result2 = Hex.toHexString(HashUtil.ripemd160("test2".getBytes()));
  assertEquals(expected2, result2);
}

代码示例来源:origin: ethereum/ethereumj

@Test /* real block hash calc */
public void test8() {
  String blockRaw = "F885F8818080A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347940000000000000000000000000000000000000000A0BCDDD284BF396739C224DBA0411566C891C32115FEB998A3E2B4E61F3F35582AA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D4934783800000808080C0C0";
  byte[] blockHashB = HashUtil.sha3(Hex.decode(blockRaw));
  String blockHash = Hex.toHexString(blockHashB);
  System.out.println(blockHash);
}

代码示例来源:origin: ethereum/ethereumj

@Test
public void testSha256_Test() {
  String expected2 = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08";
  String result2 = Hex.toHexString(HashUtil.sha256("test".getBytes()));
  assertEquals(expected2, result2);
}

代码示例来源:origin: ethereum/ethereumj

@Test
public void testSha3_Test() {
  String expected2 = "9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658";
  String result2 = Hex.toHexString(HashUtil.sha3("test".getBytes()));
  assertEquals(expected2, result2);
}

代码示例来源:origin: ethereum/ethereumj

@Test
public void test3() {
  BigInteger privKey = new BigInteger("cd244b3015703ddf545595da06ada5516628c5feadbf49dc66049c4b370cc5d8", 16);
  byte[] addr = ECKey.fromPrivate(privKey).getAddress();
  assertEquals("89b44e4d3c81ede05d0f5de8d1a68f754d73d997", Hex.toHexString(addr));
}

代码示例来源:origin: ethereum/ethereumj

@Test
public void test3() {
  logger.info("\n{}", funcJson3);
  CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson3);
  Assert.assertEquals("a4f72f5a" +
      "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb2e" +
      "00000000000000000000000000000000000000000000000000000000000004d2" +
      "000000000000000000000000000000000000000000000000000000000000007b61" +
      "000000000000000000000000000000000000000000000000000000000000007468" +
      "6520737472696e6700000000000000000000000000000000000000000000",
      Hex.toHexString(function.encode(-1234, 1234, 123, "a", "the string")));
}

代码示例来源:origin: ethereum/ethereumj

/**
 * Test genesis with short nonce
 * + alloc addresses with 0x
 */
@Test
public void testGenesisShortNonce() {
  Block genesis = loadGenesisFromFile("/genesis/nonce-messy2.json");
  assertEquals(MESSY_NONCE_GENESIS_HASH, Hex.toHexString(genesis.getHash()));
  assertEquals(MESSY_NONCE_GENESIS_RLP, Hex.toHexString(genesis.getEncoded()));
}

代码示例来源:origin: ethereum/ethereumj

@Test
public void testSha3_EmptyString() {
  String expected1 = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470";
  String result1 = Hex.toHexString(HashUtil.sha3(new byte[0]));
  assertEquals(expected1, result1);
}

代码示例来源:origin: ethereum/ethereumj

@Test
public void testECKey() {
  ECKey key = new ECKey();
  assertTrue(key.isPubKeyCanonical());
  assertNotNull(key.getPubKey());
  assertNotNull(key.getPrivKeyBytes());
  log.debug(Hex.toHexString(key.getPrivKeyBytes()) + " :Generated privkey");
  log.debug(Hex.toHexString(key.getPubKey()) + " :Generated pubkey");
}

代码示例来源:origin: ethereum/ethereumj

private void assertInvalidNodeId(String nodeId) {
  String hexEncodedNodeId = Hex.toHexString(nodeId.getBytes());
  ActivePeer nodeWithInvalidNodeId = ActivePeer.asNodeWithId("node-1", "1.1.1.1", hexEncodedNodeId);
  Config config = createActivePeersConfig(nodeWithInvalidNodeId);
  SystemProperties props = new SystemProperties();
  try {
    props.overrideParams(config);
    fail("Should've thrown exception for invalid node id");
  } catch (RuntimeException ignore) { }
}

代码示例来源:origin: ethereum/ethereumj

@Test // rlp decode
public void test_2() {
  LogInfo log = new LogInfo(Hex.decode("d5ccd26ba09ce1d85148b5081fa3ed77949417be"), null, null);
  assertEquals("d794d5ccd26ba09ce1d85148b5081fa3ed77949417bec080", Hex.toHexString(log.getEncoded()));
  logger.info("{}", log);
}

代码示例来源:origin: ethereum/ethereumj

private void assertInvalidPrivateKey(byte[] privateKey) {
  String hexEncodedPrivateKey = Hex.toHexString(privateKey);
  SystemProperties props = new SystemProperties();
  try {
    props.overrideParams("peer.privateKey", hexEncodedPrivateKey);
    props.privateKey();
    fail("Should've thrown exception for invalid private key");
  } catch (RuntimeException ignore) { }
}

代码示例来源:origin: ethereum/ethereumj

@Test
public void testSingleItem() {
  StringTrie trie = new StringTrie(mockDb);
  trie.put("A", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
  assertEquals("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab", Hex.toHexString(trie.getRootHash()));
}

代码示例来源:origin: ethereum/ethereumj

@Ignore //TODO #POC9
@Test
public void testGenesisAccounts() {
  Trie trie = generateGenesisState();
  assertEquals(GENESIS_STATE_ROOT, Hex.toHexString(trie.getRootHash()));
}

相关文章