/** * @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); }
public static byte[] binToNibblesNoTerminator(byte[] str) { byte[] hexEncoded = encode(str); for (int i = 0; i < hexEncoded.length; ++i){ byte b = hexEncoded[i]; hexEncoded[i] = hexMap.get((char) b); } return hexEncoded; } }
private static String val2str(byte[] val, boolean shortHash) { String ret = Hex.toHexString(val); if (val.length > 16) { ret = ret.substring(0,10) + "... len " + val.length; } return "\"" + ret + "\""; } }
@Override public byte[] next() { return Hex.decode(scanner.nextLine()); } };
@Override public void serialize(byte[] memory, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeString(Hex.toHexString(memory)); } }
@ValidateMe public byte[] getMineExtraData() { byte[] bytes; if (config.hasPath("mine.extraDataHex")) { bytes = Hex.decode(config.getString("mine.extraDataHex")); } else { bytes = config.getString("mine.extraData").getBytes(); } if (bytes.length > 32) throw new RuntimeException("mine.extraData exceed 32 bytes length: " + bytes.length); return bytes; }
public static void main(String[] args) throws Exception { ECKey k = ECKey.fromPrivate(Hex.decode("6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ec")); System.out.println(Hex.toHexString(k.getPrivKeyBytes())); System.out.println(Hex.toHexString(k.getAddress())); System.out.println(Hex.toHexString(k.getNodeId())); }
private boolean parseTxs(byte[] expectedRoot, RLPList txTransactions, boolean validate) { byte[] rootHash = parseTxs(txTransactions, validate); String calculatedRoot = Hex.toHexString(rootHash); if (!calculatedRoot.equals(Hex.toHexString(expectedRoot))) { logger.debug("Transactions trie root validation failed for block #{}", this.header.getNumber()); return false; } return true; }
private static List<Block> loadBlocks(String path) throws URISyntaxException, IOException { URL url = ClassLoader.getSystemResource(path); File file = new File(url.toURI()); List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); List<Block> blocks = new ArrayList<>(strData.size()); for (String rlp : strData) { blocks.add(new Block(decode(rlp))); } return blocks; }
public static void main(String[] args) throws Exception { ECKey k = ECKey.fromPrivate(Hex.decode("6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ec")); System.out.println(Hex.toHexString(k.getPrivKeyBytes())); System.out.println(Hex.toHexString(k.getAddress())); System.out.println(Hex.toHexString(k.getNodeId())); } }
static String formatBinData(byte[] binData, int startPC) { StringBuilder ret = new StringBuilder(); for (int i = 0; i < binData.length; i += 16) { ret.append(Utils.align("" + Integer.toHexString(startPC + (i)) + ":", ' ', 8, false)); ret.append(Hex.toHexString(binData, i, min(16, binData.length - i))).append('\n'); } return ret.toString(); }
private static void checkKeys(Map<byte[], byte[]> map, String ... keys) { Assert.assertEquals(keys.length, map.size()); for (String key : keys) { assertTrue(map.containsKey(Hex.decode(key))); } }
@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); }
public ProgramTrace(SystemProperties config, ProgramInvoke programInvoke) { if (programInvoke != null && config.vmTrace()) { contractAddress = Hex.toHexString(programInvoke.getOwnerAddress().getLast20Bytes()); } }
@Test public void test_1() { byte[] payload = Hex.decode("f90144f9013Bf90136a0d8faffbc4c4213d35db9007de41cece45d95db7fd6c0f129e158baa888c48eefa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794baedba0480e1b882b606cd302d8c4f5701cabac7a0c7d4565fb7b3d98e54a0dec8b76f8c001a784a5689954ce0aedcc1bbe8d13095a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b8400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083063477825fc88609184e72a0008301e8488084543ffee680a00de0b9d4a0f0c23546d31f1f70db00d25cf6a7af79365b4e058e4a6a3b69527bc0c0850177ddbebe"); NewBlockMessage newBlockMessage = new NewBlockMessage(payload); logger.trace("{}", newBlockMessage); }
@Test public void decryptAECSIC(){ ECKey key = ECKey.fromPrivate(Hex.decode("abb51256c1324a1350598653f46aa3ad693ac3cf5d05f36eba3f495a1f51590f")); byte[] payload = key.decryptAES(Hex.decode("84a727bc81fa4b13947dc9728b88fd08")); System.out.println(Hex.toHexString(payload)); }
private String str(Object obj) { if (obj == null) return null; byte[] data; if (obj instanceof DataWord) { data = ((DataWord) obj).getData(); } else { data = (byte[]) obj; } return Hex.toHexString(data); }
@Test public void identityTest1() { DataWord addr = DataWord.of("0000000000000000000000000000000000000000000000000000000000000004"); PrecompiledContract contract = PrecompiledContracts.getContractForAddress(addr, eip160Config); byte[] data = Hex.decode("112233445566"); byte[] expected = Hex.decode("112233445566"); byte[] result = contract.execute(data).getRight(); assertArrayEquals(expected, result); }
@Test public void blockTest1() { String rlp = "f90214a0a9c93d6bcd5dbcc94e0f467c88c59851b0951990c1c340c7b20aa967758ecd87a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ee0250c19ad59305b2bdb61f34b45b72fe37154fa0ed230be6c9531d27a387fa5ca2cb2e70848d5de33636ae2a28d5e9e623a3089da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000831116b881d9850ec4a4290b8084567406d39ad983010302844765746887676f312e352e318777696e646f7773a09a518a25af220fb8afe23bcafd71e4a0dba0da38972e962b07ed89dab34ac2748872311081e40c488a | f90214a01e479ea9dc53e675780469952ea87d531eb3d47808e2b57339055bdc6e61ae57a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ee0250c19ad59305b2bdb61f34b45b72fe37154fa0ea92e8c9e36ffe81be59f06af1a3b4b18b778838d4fac19f4dfeb08a5a1046dfa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000831118da81da850ec0f300028084567406dd9ad983010302844765746887676f312e352e318777696e646f7773a056bacad6b399e5e39f5168080941d54807f25984544f6bc885bbf1a0ffd0a0298856ceeb676b74d420 | " + "f90214a0b7992b18db1b3514b90376fe96235bc73db9eba3cb21ecb190d34e9c680c914fa06ab8465069b6d6a758c73894d6fbd2ad98f9c551a7a99672aedba3b12d1e76f594ee0250c19ad59305b2bdb61f34b45b72fe37154fa0499179489d7c04a781c3fd8b8b0f0a04030fd2057a11e86e6a12e4baa07dfdd6a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083111afd81db850ebd42c3438084567406e19ad983010302844765746887676f312e352e318777696e646f7773a04d78ab8e21ea8630f52a60ed60d945c7bbb8267777d28a98612b77a673663430886b676858a8d6b99a | f90204a08680005ea64540a769286d281cb931a97e7abed2611f00f2c6f47a7aaad5faa8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479450b8f981ce93fd5b81b844409169148428400bf3a0bf55a6e82564fb532316e694838dae38d21fa80bc8af1867e418cb26bcdf0e61a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000831118da81dc850ebd42c3438084567406f58acccccccccccccccccccca04c2135ea0bb1f148303b201141df207898fa0897e3fb48fe661cda3ba2880da388b4ce6cb5535077af | f90204a05897e0e01ed54cf189751c6dd7b0107b2b3b1c841cb7d9bdb6f2aca6ff770c17a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479450b8f981ce93fd5b81b844409169148428400bf3a01ad754d90de6789c4fa5708992d9f089165e5047d52e09abc22cf49428af23cda056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000831116b781dd850ebd42c3438084567407048acccccccccccccccccccca0b314fab93d91a0adea632fd58027cb39857a0ad188c473f41a640052a6a0141d88d64656f7bb5f1066"; for (String s : rlp.split("\\|")) { BlockHeader blockHeader = new BlockHeader(Hex.decode(s)); System.out.println(Hex.toHexString(blockHeader.getHash()).substring(0, 6)); System.out.println(blockHeader); } }
@Test public void encodeBigIntegerEdge_1() { BigInteger integer = new BigInteger("80", 10); byte[] encodedData = encodeBigInteger(integer); System.out.println(Hex.toHexString(encodedData)); }