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

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

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

origin: yggdrash/yggdrash

/**
 * Verifies the given R/S pair (signature) against a hash using the public key.
 *
 * @param sigHash   -
 * @param signature -
 * @return -
 */
public boolean verify(byte[] sigHash, ECDSASignature signature) {
  return ECKey.verify(sigHash, signature, getPubKey());
}
origin: yggdrash/yggdrash

/**
 * Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key.
 *
 * @param data      Hash of the data to verify.
 * @param signature signature.
 * @param pub       The public key bytes to use.
 * @return -
 */
public static boolean verify(byte[] data, byte[] signature, byte[] pub) {
  return verify(data, ECDSASignature.decodeFromDER(signature), pub);
}
origin: yggdrash/yggdrash

/**
 * Verify the signature with hashed data.
 *
 * @param hashedData hashed Data
 * @param signature  signature
 * @return verification result
 */
boolean verifyHashedData(byte[] hashedData, byte[] signature) {
  ECKey.ECDSASignature sig = new ECKey.ECDSASignature(signature);
  return key.verify(hashedData, sig);
}
origin: yggdrash/yggdrash

/**
 * Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key.
 *
 * @param data      Hash of the data to verify.
 * @param signature signature.
 * @return -
 */
public boolean verify(byte[] data, byte[] signature) {
  return ECKey.verify(data, signature, getPubKey());
}
origin: yggdrash/yggdrash

/**
 * Verify the signature with plain data.
 *
 * @param data      plain data for signed
 * @param signature signature
 * @return verification result
 */
public boolean verify(byte[] data, byte[] signature) {
  ECKey.ECDSASignature sig = new ECKey.ECDSASignature(signature);
  return key.verify(HashUtil.sha3(data), sig);
}
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
public void testVerifySignature1() {
  ECKey key = ECKey.fromPublicOnly(pubKey);
  BigInteger r = new BigInteger("95350169487015575001444507567851457309689354890536757640816472151471942911739");
  BigInteger s = new BigInteger("53263359985948886716508128220321578640585687230908938312863706887350789467339");
  ECDSASignature sig = ECDSASignature.fromComponents(r.toByteArray(), s.toByteArray(), (byte) 28);
  assertTrue(key.verify(HashUtil.sha3(exampleMessage.getBytes()), sig));
}
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 testVerifySignature5() {
  ECKey key = ECKey.fromPrivate(privateKey);
  byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
  ECDSASignature signature = key.sign(messageHash);
  assertTrue(key.verify(messageHash, signature));
}
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

private void testProviderRoundTrip(Provider provider) {
  ECKey key = new ECKey(provider, secureRandom);
  String message = "The quick brown fox jumps over the lazy dog.";
  byte[] input = HashUtil.sha3(message.getBytes());
  ECDSASignature sig = key.sign(input);
  assertTrue(sig.validateComponents());
  assertTrue(key.verify(input, sig));
}
origin: yggdrash/yggdrash

@Test
public void testSignVerify() {
  ECKey key = ECKey.fromPrivate(privateKey);
  String message = "This is an example of a signed message.";
  byte[] input = HashUtil.sha3(message.getBytes());
  ECDSASignature sig = key.sign(input);
  assertTrue(sig.validateComponents());
  assertTrue(key.verify(input, sig));
}
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));
}
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));
}
io.yggdrash.common.cryptoECKeyverify

Javadoc

Verifies the given R/S pair (signature) against a hash using the public key.

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
  • signatureToKey
    Compute the key that signed the given signature.
  • sign,
  • signatureToKey,
  • check,
  • computeAddress,
  • decompressKey,
  • equals,
  • extractPublicKey,
  • fromNodeId,
  • getPubKeyPoint

Popular in Java

  • Updating database using SQL prepared statement
  • setRequestProperty (URLConnection)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • addToBackStack (FragmentTransaction)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Top PhpStorm plugins
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