Examples of ECKey


Examples of org.ethereum.crypto.ECKey

    assertArrayEquals(Hex.decode(address), key.getAddress());
  }

  @Test
  public void testToString() {
        ECKey key = ECKey.fromPrivate(BigInteger.TEN); // An example private key.
        assertEquals("pub:04a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7", key.toString());
  }
View Full Code Here

Examples of org.ethereum.crypto.ECKey

  }

  @Test
  public void testEthereumSign() throws IOException {
    // TODO: Understand why key must be decompressed for this to work
    ECKey key = ECKey.fromPrivate(privateKey).decompress();
        System.out.println("Secret\t: " + Hex.toHexString(key.getPrivKeyBytes()));
        System.out.println("Pubkey\t: " + Hex.toHexString(key.getPubKey()));
        System.out.println("Data\t: " + exampleMessage);
        byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
        ECDSASignature signature = key.sign(messageHash);
        String output = signature.toBase64();
        System.out.println("Signtr\t: " + output + " (Base64, length: " + output.length() + ")");
        assertEquals(sigBase64, output);
  }
View Full Code Here

Examples of org.ethereum.crypto.ECKey

        assertEquals(sigBase64, output);
  }
 
    @Test
    public void testVerifySignature1() {
      ECKey key = ECKey.fromPublicOnly(pubKey);
        BigInteger r = new BigInteger("28157690258821599598544026901946453245423343069728565040002908283498585537001");
        BigInteger s = new BigInteger("30212485197630673222315826773656074299979444367665131281281249560925428307087");
        ECDSASignature sig = ECDSASignature.fromComponents(r.toByteArray(), s.toByteArray(), (byte) 28);
        key.verify(HashUtil.sha3(exampleMessage.getBytes()), sig);
    }
View Full Code Here

Examples of org.ethereum.crypto.ECKey

        BigInteger r = new BigInteger("c52c114d4f5a3ba904a9b3036e5e118fe0dbb987fe3955da20f2cd8f6c21ab9c", 16);
        BigInteger s = new BigInteger("6ba4c2874299a55ad947dbc98a25ee895aabf6b625c26c435e84bfd70edf2f69", 16);
        ECDSASignature sig = ECDSASignature.fromComponents(r.toByteArray(), s.toByteArray(), (byte) 0x1b);
        byte[] rawtx = Hex.decode("f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480");
    try {
      ECKey key = ECKey.signatureToKey(HashUtil.sha3(rawtx), sig.toBase64());
      System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
      System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
      assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", Hex.toHexString(key.getAddress()));
      key.verify(HashUtil.sha3(rawtx), sig);
    } catch (SignatureException e) {
      fail();
    }
    }
View Full Code Here

Examples of org.ethereum.crypto.ECKey

    public void testVerifySignature3() throws SignatureException {

        byte[] rawtx = Hex.decode("f86e80893635c9adc5dea000008609184e72a00082109f9479b08ad8787060333663d19704909ee7b1903e58801ba0899b92d0c76cbf18df24394996beef19c050baa9823b4a9828cd9b260c97112ea0c9e62eb4cf0a9d95ca35c8830afac567619d6b3ebee841a3c8be61d35acd8049");

        Transaction tx = new Transaction(rawtx);
        ECKey key = ECKey.signatureToKey(HashUtil.sha3(rawtx), tx.getSignature().toBase64());

        System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
        System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));

        //  sender: CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826
        // todo: add test assertion when the sign/verify part actually works.
    }
View Full Code Here

Examples of org.ethereum.crypto.ECKey

        // Check that we never generate an S value that is larger than half the curve order. This avoids a malleability
        // issue that can allow someone to change a transaction [hash] without invalidating the signature.
        final int ITERATIONS = 10;
        ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(ITERATIONS));
        List<ListenableFuture<ECKey.ECDSASignature>> sigFutures = Lists.newArrayList();
        final ECKey key = new ECKey();
        for (byte i = 0; i < ITERATIONS; i++) {
            final byte[] hash = HashUtil.sha3(new byte[]{i});
            sigFutures.add(executor.submit(new Callable<ECKey.ECDSASignature>() {
                @Override
                public ECKey.ECDSASignature call() throws Exception {
                    return key.doSign(hash);
                }
            }));
        }
        List<ECKey.ECDSASignature> sigs = Futures.allAsList(sigFutures).get();
        for (ECKey.ECDSASignature signature : sigs) {
View Full Code Here

Examples of org.ethereum.crypto.ECKey

        assertEquals(sigs.get(0).hashCode(), duplicate.hashCode());
    }
 
    @Test
    public void testSignVerify() {
      ECKey key = ECKey.fromPrivate(privateKey);
      String message = new String("This is an example of a signed message.");
      ECDSASignature output = key.doSign(message.getBytes());
      assertTrue(key.verify(message.getBytes(), output));
    }
View Full Code Here

Examples of org.ethereum.crypto.ECKey

    assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey6));
  }
 
    @Test
    public void keyRecovery() throws Exception {
        ECKey key = new ECKey();
        String message = "Hello World!";
        byte[] hash = HashUtil.sha256(message.getBytes());
        ECKey.ECDSASignature sig = key.doSign(hash);
        key = ECKey.fromPublicOnly(key.getPubKeyPoint());
        boolean found = false;
        for (int i = 0; i < 4; i++) {
            ECKey key2 = ECKey.recoverFromSignature(i, sig, hash, true);
            checkNotNull(key2);
            if (key.equals(key2)) {
                found = true;
                break;
            }
View Full Code Here

Examples of org.ethereum.crypto.ECKey

        //python taken exact data
        String txRLPRawData = "a9e880872386f26fc1000085e8d4a510008203e89413978aee95f38490e9769c39b2773ed763d9cd5f80";
        // String txRLPRawData = "f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480";

        byte[] cowPrivKey = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4");
        ECKey key = ECKey.fromPrivate(cowPrivKey);

        byte[] data    = Hex.decode(txRLPRawData);

        // step 1: serialize + RLP encode
        // step 2: hash = sha3(step1)
        byte[] txHash = HashUtil.sha3(data);

        String signature = key.doSign(txHash).toBase64();
        System.out.println(signature);
    }
View Full Code Here

Examples of org.ethereum.crypto.ECKey

    }
 
  @Test
  public void testSignedMessageToKey() throws SignatureException {
    byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
      ECKey key = ECKey.signatureToKey(messageHash, sigBase64);
      assertNotNull(key);
      assertArrayEquals(pubKey, key.getPubKey());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.