当前位置: 首页>>代码示例>>Java>>正文


Java Hex类代码示例

本文整理汇总了Java中org.spongycastle.util.encoders.Hex的典型用法代码示例。如果您正苦于以下问题:Java Hex类的具体用法?Java Hex怎么用?Java Hex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Hex类属于org.spongycastle.util.encoders包,在下文中一共展示了Hex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Address

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
@PrepareForTest({ ScriptBuilder.class })
@Test
public void Address() {
    // Since we can't mock both Address and ScriptBuilder at the same time (due to PowerMockito limitations)
    // we use a well known P2SH and its corresponding address
    // and just mock the ScriptBuilder
    // a914896ed9f3446d51b5510f7f0b6ef81b2bde55140e87 => 2N5muMepJizJE1gR7FbHJU6CD18V3BpNF9p
    final List<Integer> calls = new ArrayList<>();
    PowerMockito.mockStatic(ScriptBuilder.class);
    PowerMockito.when(ScriptBuilder.createP2SHOutputScript(any(int.class), any(List.class))).thenAnswer((invocationOnMock) -> {
        calls.add(0);
        int numberOfSignaturesRequired = invocationOnMock.getArgumentAt(0, int.class);
        List<BtcECKey> publicKeys = invocationOnMock.getArgumentAt(1, List.class);
        Assert.assertEquals(4, numberOfSignaturesRequired);
        Assert.assertEquals(6, publicKeys.size());
        for (int i = 0; i < sortedPublicKeys.size();i ++) {
            Assert.assertTrue(Arrays.equals(sortedPublicKeys.get(i).getPubKey(), publicKeys.get(i).getPubKey()));
        }
        return new Script(Hex.decode("a914896ed9f3446d51b5510f7f0b6ef81b2bde55140e87"));
    });

    Assert.assertEquals("2N5muMepJizJE1gR7FbHJU6CD18V3BpNF9p", federation.getAddress().toBase58());
    Assert.assertEquals("2N5muMepJizJE1gR7FbHJU6CD18V3BpNF9p", federation.getAddress().toBase58());
    // Make sure the address creation happens only once
    Assert.assertEquals(1, calls.size());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:FederationTest.java

示例2: test1

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
@Test
public void test1() {
    String helloMessageRaw = "f87902a5457468657265756d282b2b292f76302e372e392f52656c656173652f4c696e75782f672b2bccc58365746827c583736868018203e0b8401fbf1e41f08078918c9f7b6734594ee56d7f538614f602c71194db0a1af5a77f9b86eb14669fe7a8a46a2dd1b7d070b94e463f4ecd5b337c8b4d31bbf8dd5646";

    byte[] payload = Hex.decode(helloMessageRaw);
    HelloMessage helloMessage = new HelloMessage(payload);
    logger.info(helloMessage.toString());

    assertEquals(P2pMessageCodes.HELLO, helloMessage.getCommand());
    assertEquals(2, helloMessage.getP2PVersion());
    assertEquals("Ethereum(++)/v0.7.9/Release/Linux/g++", helloMessage.getClientId());
    assertEquals(2, helloMessage.getCapabilities().size());
    assertEquals(992, helloMessage.getListenPort());
    assertEquals(
            "1fbf1e41f08078918c9f7b6734594ee56d7f538614f602c71194db0a1af5a77f9b86eb14669fe7a8a46a2dd1b7d070b94e463f4ecd5b337c8b4d31bbf8dd5646",
            helloMessage.getPeerId());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:18,代码来源:HelloMessageTest.java

示例3: prepareData

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
@Ignore("long stress test")
@Test // loads blocks from file and store them into disk DB
public void prepareData() throws URISyntaxException, IOException {
    URL dataURL = ClassLoader.getSystemResource("blockstore/big_data.dmp");

    File file = new File(dataURL.toURI());

    BufferedReader reader = new BufferedReader(new FileReader(file));
    String blockRLP;
    while(null != (blockRLP = reader.readLine())) {
        Block block = new Block(
                Hex.decode(blockRLP)
        );
        blockSource.put(block.getHash(), block);

        if (block.getNumber() % 10000 == 0)
            logger.info(
                    "adding block.hash: [{}] block.number: [{}]",
                    block.getShortHash(),
                    block.getNumber()
            );
    }
    logger.info("total blocks loaded: {}", blockSource.size());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:BlockStressTest.java

示例4: valid

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
public static List<String> valid(String origOutput, String postOutput){

        List<String> results = new ArrayList<>();

        if (postOutput.startsWith("#")) {
            int postLen = Integer.parseInt(postOutput.substring(1));
            if (postLen != origOutput.length() / 2) {
                results.add("Expected output length: " + postLen + ", actual: " + origOutput.length() / 2);
            }
        } else {
            String postOutputFormated = Hex.toHexString(parseData(postOutput));

            if (!origOutput.equals(postOutputFormated)) {
                String formattedString = String.format("HReturn: wrong expected: %s, current: %s",
                        postOutputFormated, origOutput);
                results.add(formattedString);
            }
        }

        return results;
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:22,代码来源:OutputValidator.java

示例5: testCALLDATACOPY_4

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
@Test // CALLDATACOPY OP
public void testCALLDATACOPY_4() {

    VM vm = new VM();
    program =
            new Program(Hex.decode("60406000600437"), invoke);
    String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" +
            "000000A100000000000000000000000000000000000000000000000000000000" +
            "000000B100000000000000000000000000000000000000000000000000000000";

    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);

    assertEquals(m_expected, Hex.toHexString(program.getMemory()).toUpperCase());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:18,代码来源:VMCustomTest.java

示例6: testDiv

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
@Test
public void testDiv() {
    byte[] one = new byte[32];
    one[30] = 0x01;
    one[31] = 0x2c; // 0x000000000000000000000000000000000000000000000000000000000000012c

    byte[] two = new byte[32];
    two[31] = 0x0f; // 0x000000000000000000000000000000000000000000000000000000000000000f

    DataWord x = new DataWord(one);
    DataWord y = new DataWord(two);
    x.div(y);

    assertEquals(32, x.getData().length);
    assertEquals("0000000000000000000000000000000000000000000000000000000000000014", Hex.toHexString(x.getData()));
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:17,代码来源:DataWordTest.java

示例7: testEXP_1

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
@Ignore //TODO #POC9
@Test // EXP OP
public void testEXP_1() {

    VM vm = new VM();
    program = new Program(Hex.decode("600360020a"), invoke);
    String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000008";

    vm.step(program);
    vm.step(program);
    vm.step(program);

    DataWord item1 = program.stackPop();
    long gas = program.getResult().getGasUsed();

    assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase());
    assertEquals(4, gas);
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:19,代码来源:VMTest.java

示例8: execute

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
public void execute(){

        byte[] key = Hex.decode(this.key);
        byte[] cipher = Hex.decode(this.cipher);

        ECKey ecKey = ECKey.fromPrivate(key);

        byte[] resultPayload = new byte[0];
        if (decryption_type.equals("aes_ctr"))
            resultPayload = ecKey.decryptAES(cipher);

        if (decryption_type.equals("ecies_sec1_altered"))
            try {
                resultPayload = ECIESCoder.decrypt(new BigInteger(Hex.toHexString(key), 16), cipher);
            } catch (Throwable e) {e.printStackTrace();}

        if (!Hex.toHexString(resultPayload).equals(payload)){
            String error = String.format("payload should be: %s, but got that result: %s  ",
                    payload, Hex.toHexString(resultPayload));
            logger.info(error);

            System.exit(-1);
        }
    }
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:CryptoTestCase.java

示例9: mock_RLP_decode2_forMapOfHashesToLong

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
private void mock_RLP_decode2_forMapOfHashesToLong() {
    // Plain list with first elements being the size
    // Sizes are 1 byte long
    // e.g., for list [a,b,c] and a.size = 5, b.size = 7, c.size = 4, then:
    // 03050704[a bytes][b bytes][c bytes]
    when(RLP.decode2(any(byte[].class))).then((InvocationOnMock invocation) -> {
        RLPList result = new RLPList();
        byte[] arg = invocation.getArgumentAt(0, byte[].class);
        // Even byte -> hash of 64 bytes with same char from byte
        // Odd byte -> long from byte
        for (int i = 0; i < arg.length; i++) {
            byte[] element;
            if (i%2 == 0) {
                element = Hex.decode(charNTimes((char) arg[i], 64));
            } else {
                element = new byte[]{arg[i]};
            }
            result.add(() -> element);
        }
        return new ArrayList<>(Arrays.asList(result));
    });
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:23,代码来源:BridgeSerializationUtilsTest.java

示例10: getFederationSpendWallet

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
@Test
public void getFederationSpendWallet() throws UTXOProviderException {
    NetworkParameters regTestParameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
    Federation federation = new Federation(Arrays.asList(new BtcECKey[]{
            BtcECKey.fromPublicOnly(Hex.decode("036bb9eab797eadc8b697f0e82a01d01cabbfaaca37e5bafc06fdc6fdd38af894a")),
            BtcECKey.fromPublicOnly(Hex.decode("031da807c71c2f303b7f409dd2605b297ac494a563be3b9ca5f52d95a43d183cc5"))
    }), Instant.ofEpochMilli(5005L), 0L, regTestParameters);
    Context mockedBtcContext = mock(Context.class);
    when(mockedBtcContext.getParams()).thenReturn(regTestParameters);

    List<UTXO> mockedUtxos = new ArrayList<>();
    mockedUtxos.add(mock(UTXO.class));
    mockedUtxos.add(mock(UTXO.class));
    mockedUtxos.add(mock(UTXO.class));

    Wallet wallet = BridgeUtils.getFederationSpendWallet(mockedBtcContext, federation, mockedUtxos);
    Assert.assertEquals(BridgeBtcWallet.class, wallet.getClass());
    assertIsWatching(federation.getAddress(), wallet, regTestParameters);
    CoinSelector selector = wallet.getCoinSelector();
    Assert.assertEquals(RskAllowUnconfirmedCoinSelector.class, selector.getClass());
    UTXOProvider utxoProvider = wallet.getUTXOProvider();
    Assert.assertEquals(RskUTXOProvider.class, utxoProvider.getClass());
    Assert.assertEquals(mockedUtxos, utxoProvider.getOpenTransactionOutputs(Collections.emptyList()));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:BridgeUtilsTest.java

示例11: dumpState

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
@SuppressWarnings("uncheked")
public static void dumpState(ObjectNode statesNode, String address, AccountState state, ContractDetails details) {

    List<DataWord> storageKeys = new ArrayList<>(details.getStorage().keySet());
    Collections.sort(storageKeys);

    ObjectNode account = statesNode.objectNode();
    ObjectNode storage = statesNode.objectNode();

    for (DataWord key : storageKeys) {
        storage.put("0x" + Hex.toHexString(key.getData()),
                "0x" + Hex.toHexString(details.getStorage().get(key).getNoLeadZeroesData()));
    }

    if (state == null) {
        state = AccountState.EMPTY;
    }

    account.put("balance", state.getBalance() == null ? "0" : state.getBalance().toString());
    account.put("code", details.getCode() == null ? "0x" : "0x" + Hex.toHexString(details.getCode()));
    account.put("nonce", state.getNonce() == null ? "0" : state.getNonce().toString());
    account.set("storage", storage);
    account.put("storage_root", state.getStateRoot() == null ? "" : Hex.toHexString(state.getStateRoot()));

    statesNode.set(address, account);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:JSONHelper.java

示例12: addAndGetTransactionWith238AsIndex

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
@Test
public void addAndGetTransactionWith238AsIndex() {
    ReceiptStore store = new ReceiptStoreImpl(new HashMapDB());

    TransactionReceipt receipt = createReceipt();
    byte[] blockHash = Hex.decode("0102030405060708");

    store.add(blockHash, 238, receipt);

    TransactionInfo result = store.get(receipt.getTransaction().getHash());

    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getBlockHash());
    Assert.assertArrayEquals(blockHash, result.getBlockHash());
    Assert.assertEquals(238, result.getIndex());
    Assert.assertArrayEquals(receipt.getEncoded(), result.getReceipt().getEncoded());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:18,代码来源:ReceiptStoreImplTest.java

示例13: testSGT_2

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
@Test  // SGT OP
public void testSGT_2() {

    VM vm = new VM();
    program = new Program(Hex.decode("7F000000000000000000000000000000000000000000000000000000000000001E" + //   30
            "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" + // -170
            "13"), invoke);

    String expected = "0000000000000000000000000000000000000000000000000000000000000000";

    vm.step(program);
    vm.step(program);
    vm.step(program);

    assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase());
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:17,代码来源:VMTest.java

示例14: testRETURN_1

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
@Test // RETURN OP
public void testRETURN_1() {

    VM vm = new VM();
    program = new Program(Hex.decode("61123460005260206000F3"), invoke);
    String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000001234";

    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);

    assertEquals(s_expected_1, Hex.toHexString(program.getResult().getHReturn()).toUpperCase());
    assertTrue(program.isStopped());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:18,代码来源:VMTest.java

示例15: testSWAPN_1

import org.spongycastle.util.encoders.Hex; //导入依赖的package包/类
/**
 * Generic test function for SWAP1-16
 *
 * @param n in SWAPn
 */
private void testSWAPN_1(int n) {

    VM vm = new VM();
    byte operation = (byte) (OpCode.SWAP1.val() + n - 1);

    String programCode = "";
    String top = new DataWord(0x10 + n).toString();
    for (int i = n; i > -1; --i) {
        programCode += "60" + oneByteToHexString((byte) (0x10 + i));

    }

    programCode += Hex.toHexString(new byte[]{   (byte)(OpCode.SWAP1.val() + n - 1)   });

    program = new Program(ByteUtil.appendByte(Hex.decode(programCode), operation), invoke);

    for (int i = 0; i < n + 2; ++i) {
        vm.step(program);
    }

    assertEquals(n + 1, program.getStack().toArray().length);
    assertEquals(top, Hex.toHexString(program.stackPop().getData()));
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:29,代码来源:VMTest.java


注:本文中的org.spongycastle.util.encoders.Hex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。