congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ECKey.signatureToKey
Code IndexAdd Tabnine to your IDE (free)

How to use
signatureToKey
method
in
io.yggdrash.common.crypto.ECKey

Best Java code snippets using io.yggdrash.common.crypto.ECKey.signatureToKey (Showing top 15 results out of 315)

origin: yggdrash/yggdrash

@Test(expected = SignatureException.class)
public void testInvalidSignatureLength() throws SignatureException {
  // Expecting a SignatureException for invalid signature length
  byte[] messageHash = new byte[32];
  ECKey.signatureToKey(messageHash, "abcdefg");
}
origin: yggdrash/yggdrash

public static byte[] calculatePubKey(byte[] data, byte[] signature, boolean hashed) {
  ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(signature);
  byte[] hashedData = hashed ? data : HashUtil.sha3(data);
  ECKey ecKeyPub;
  try {
    ecKeyPub = ECKey.signatureToKey(hashedData, ecdsaSignature);
  } catch (SignatureException e) {
    logger.debug("Invalid signature" + e.getMessage());
    return null;
  }
  return ecKeyPub.getPubKey();
}
origin: yggdrash/yggdrash

/**
 * Get the public key.
 *
 * @return public key
 */
byte[] getPubKey() throws SignatureException {
  ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(this.signature);
  ECKey ecKeyPub = ECKey.signatureToKey(this.header.getHashForSigning(), ecdsaSignature);
  return ecKeyPub.getPubKey();
}
origin: yggdrash/yggdrash

@Test(expected = SignatureException.class)
public void testBadBase64Sig() throws SignatureException {
  // Expecting a SignatureException for invalid Base64
  byte[] messageHash = new byte[32];
  ECKey.signatureToKey(messageHash, "This is not valid Base64!");
}
origin: yggdrash/yggdrash

public byte[] getPubKey() {
  ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(this.signature);
  ECKey ecKeyPub = null;
  try {
    ecKeyPub = ECKey.signatureToKey(this.header.getHashForSigning(), ecdsaSignature);
  } catch (SignatureException e) {
    log.warn(e.getMessage());
    throw new InvalidSignatureException();
  }
  return ecKeyPub.getPubKey();
}
origin: yggdrash/yggdrash

/**
 * Verify the signature with public key
 *
 * @param data signed data
 * @param signature  signature
 * @param hashed whether hashed data or not
 * @param pubKey public key for verifying
 * @return verification result
 */
public static boolean verify(byte[] data, byte[] signature, boolean hashed, byte[] pubKey) {
  ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(signature);
  byte[] hashedData = hashed ? data : HashUtil.sha3(data);
  ECKey ecKeyPub;
  try {
    ecKeyPub = ECKey.signatureToKey(hashedData, ecdsaSignature);
  } catch (SignatureException e) {
    logger.debug("Invalid signature" + e.getMessage());
    return false;
  }
  if (pubKey != null && !Arrays.equals(ecKeyPub.getPubKey(), pubKey)) {
    logger.debug("Invalid signature");
    return false;
  }
  return ecKeyPub.verify(hashedData, ecdsaSignature);
}
origin: yggdrash/yggdrash

public boolean verify() {
  if (!this.verifyData()) {
    return false;
  }
  ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(this.signature);
  byte[] hashedHeader = this.header.getHashForSigning();
  ECKey ecKeyPub;
  try {
    ecKeyPub = ECKey.signatureToKey(hashedHeader, ecdsaSignature);
  } catch (SignatureException e) {
    throw new InvalidSignatureException(e);
  }
  return ecKeyPub.verify(hashedHeader, ecdsaSignature);
}
origin: yggdrash/yggdrash

@Test // result is a point at infinity
public void testVerifySignature4() throws SignatureException {
  byte[] hash = Hex.decode("6ee854b88dbf19846c58fd2beac582adcf28cfdd2b3a8427ac29d7b70153d35c");
  BigInteger r = new BigInteger("95350169487015575001444507567851457309689354890536757640816472151471942911739");
  BigInteger s = new BigInteger("53263359985948886716508128220321578640585687230908938312863706887350789467339");
  ECDSASignature sig = ECDSASignature.fromComponents(r.toByteArray(), s.toByteArray(), (byte) 28);
  ECKey key = ECKey.signatureToKey(hash, sig);
  assertTrue(key.verify(hash, sig));
}
origin: yggdrash/yggdrash

/**
 * Verify a transaction.(data format & signing)
 *
 * @return true(success), false(fail)
 */
public boolean verify() {
  if (!this.verifyData()) {
    return false;
  }
  ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(this.signature);
  byte[] hashedHeader = this.header.getHashForSigning();
  ECKey ecKeyPub;
  try {
    ecKeyPub = ECKey.signatureToKey(hashedHeader, ecdsaSignature);
  } catch (SignatureException e) {
    throw new InvalidSignatureException(e);
  }
  return ecKeyPub.verify(hashedHeader, ecdsaSignature);
}
origin: yggdrash/yggdrash

@Test
public void testSignedMessageToKey() throws SignatureException {
  byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
  ECKey key = ECKey.signatureToKey(messageHash, sigBase64);
  assertNotNull(key);
  assertArrayEquals(pubKey, key.getPubKey());
}
origin: yggdrash/yggdrash

public boolean verify() {
  ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(signature.getBytes());
  try {
    ECKey ecKeyPub = ECKey.signatureToKey(rawForSign.getBytes(), ecdsaSignature);
    if (ecKeyPub.verify(rawForSign.getBytes(), ecdsaSignature)) {
      return new Address(ecKeyPub.getAddress()).equals(owner);
    } else {
      return false;
    }
  } catch (SignatureException e) {
    throw new InvalidSignatureException(e);
  }
}
origin: yggdrash/yggdrash

@Test
public void testVerifySignature_Static() throws SignatureException {
  byte[] messageHash = Hex.decode("92e0d4290bba01aa0abbb4705360c751af13fdb1131b8f6f1e632c4621adac75");
  byte[] signature = Hex.decode("1cca588a8eb84d5bf6741bc6e0ccfbe1fdb05b6c624b5fe72199fa1f2e501f876c5b5f11863323a998b79a0d27714fcc8825cf357903e863396f2e2e281220de31");
  // get public key with messageHash, ECDSASignature
  ECKey.ECDSASignature sig = new ECKey.ECDSASignature(signature);
  ECKey keyFromSig = ECKey.signatureToKey(messageHash, sig);
  log.debug("address=" + Hex.toHexString(keyFromSig.getAddress()));
  byte[] pubKeyFromSig = keyFromSig.getPubKey();
  log.debug("pubKey=" + Hex.toHexString(pubKeyFromSig));
  assertArrayEquals(pubKeyFromSig, Hex.decode("0493fe448d38c77c212cce10c07ed37984c59bedac51219b70847429153063cfae0d2f42ba394ffe9d5d2d11b0c0f400ac04997c584c0ef6f2041cf20f8c2c446b"));
  // verify the sign message
  assertTrue(keyFromSig.verify(messageHash, sig));
}
origin: yggdrash/yggdrash

@Test
public void testVerifySignature2() throws SignatureException {
  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");
  byte[] rawHash = HashUtil.sha3(rawtx);
  byte[] address = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
  ECKey key = ECKey.signatureToKey(rawHash, sig);
  assertEquals(key, ECKey.signatureToKey(rawHash, sig.toBase64()));
  assertEquals(key, ECKey.recoverFromSignature(0, sig, rawHash));
  assertArrayEquals(key.getPubKey(), ECKey.recoverPubBytesFromSignature(0, sig, rawHash));
  assertArrayEquals(address, key.getAddress());
  assertArrayEquals(address, ECKey.signatureToAddress(rawHash, sig));
  assertArrayEquals(address, ECKey.signatureToAddress(rawHash, sig.toBase64()));
  assertArrayEquals(address, ECKey.recoverAddressFromSignature(0, sig, rawHash));
  assertTrue(key.verify(rawHash, sig));
}
origin: yggdrash/yggdrash

@Test
public void testGetAddressWithSig()
    throws IOException, InvalidCipherTextException, SignatureException {
  Account account = new Account();
  log.debug("Account: " + account.toString());
  log.debug("Account.address: " + Hex.toHexString(account.getAddress()));
  log.debug("Account.pubKey: " + Hex.toHexString(account.getKey().getPubKey()));
  Wallet wallet = new Wallet(account.getKey(), "tmp/path", "nodePri.key", "Aa1234567890!");
  log.debug("Wallet: " + wallet.toString());
  log.debug("Wallet.address: " + Hex.toHexString(wallet.getAddress()));
  log.debug("Wallet.pubKey: " + Hex.toHexString(wallet.getPubicKey()));
  TransactionHusk txHusk1 = createTx(wallet);
  log.debug("Test Transaction1: " + txHusk1.toString());
  log.debug("Test Transaction1 Address: " + txHusk1.getAddress());
  assertThat(txHusk1.verify()).isTrue();
  assertThat(wallet.getAddress()).isEqualTo(account.getAddress());
  assertThat(wallet.getAddress()).isEqualTo(txHusk1.getAddress().getBytes());
  byte[] hashedRawData = txHusk1.getHashForSigning().getBytes();
  log.debug("hashedRawData: " + Hex.toHexString(hashedRawData));
  byte[] signatureBin = txHusk1.getInstance().getSignature().toByteArray();
  log.debug("signatureBin: " + Hex.toHexString(signatureBin));
  ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(signatureBin);
  ECKey key = ECKey.signatureToKey(hashedRawData, ecdsaSignature);
  byte[] address = key.getAddress();
  byte[] pubKey = key.getPubKey();
  log.debug("address: " + Hex.toHexString(address));
  log.debug("pubKey: " + Hex.toHexString(pubKey));
  assertThat(account.getAddress()).isEqualTo(address);
  assertThat(account.getKey().getPubKey()).isEqualTo(pubKey);
}
origin: yggdrash/yggdrash

@Test
public void testVerifySignature6() throws SignatureException {
  // generate ECkey object with privateKey
  ECKey key = ECKey.fromPrivate(privateKey);
  // check public key with pubKey
  assertArrayEquals(pubKey, key.getPubKey());
  // generate messageHash with exampleMessage
  byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
  // generate ECDSASignature with ECKey, messageHash
  ECDSASignature signature = key.sign(messageHash);
  // verify the sign message
  assertTrue(key.verify(messageHash, signature));
  // get public key with messageHash, ECDSASignature
  ECKey keyFromSig = ECKey.signatureToKey(messageHash, signature);
  byte[] pubKeyFromSig = keyFromSig.getPubKey();
  assertArrayEquals(pubKey, pubKeyFromSig);
  // verify the sign message
  assertTrue(keyFromSig.verify(messageHash, signature));
}
io.yggdrash.common.cryptoECKeysignatureToKey

Javadoc

Compute the key that signed the given signature.

Popular methods of ECKey

  • <init>
    Generates an entirely new keypair with the given SecureRandom object. BouncyCastle will be used as
  • doSign
    Signs the given hash and returns the R and S components as BigIntegers and put them in ECDSASignatur
  • fromPrivate
    Creates an ECKey given the private key only.
  • fromPublicOnly
    Creates an ECKey that cannot be used for signing, only verifying signatures, from the given encoded
  • getAddress
    Gets the address form of the public key.
  • getNodeId
    Generates the NodeID based on this key, that is the public key without first format byte
  • getPrivKeyBytes
    Returns a 32 byte array containing the private key, or null if the key is encrypted or public only
  • getPubKey
    Gets the encoded public key value.
  • isPubKeyCanonical
    Returns true if the given pubkey is canonical, i.e. the correct length taking into wallet compressio
  • recoverPubBytesFromSignature
    Given the components of a signature and a selector value, recover and return the public key that gen
  • sign
    Takes the keccak hash (32 bytes) of data and returns the ECDSA signature
  • verify
    Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key.
  • sign,
  • verify,
  • check,
  • computeAddress,
  • decompressKey,
  • equals,
  • extractPublicKey,
  • fromNodeId,
  • getPubKeyPoint

Popular in Java

  • Finding current android device location
  • compareTo (BigDecimal)
  • setRequestProperty (URLConnection)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now