Package org.ethereum.crypto.ECKey

Examples of org.ethereum.crypto.ECKey.ECDSASignature


    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


    @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

   
    @Test
    public void testVerifySignature2() {
        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) {
View Full Code Here

 
    @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

TOP

Related Classes of org.ethereum.crypto.ECKey.ECDSASignature

Copyright © 2018 www.massapicom. 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.