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

How to use
io.yggdrash.common.crypto.ECKey
constructor

Best Java code snippets using io.yggdrash.common.crypto.ECKey.<init> (Showing top 14 results out of 315)

origin: yggdrash/yggdrash

/**
 * Creates an ECKey that cannot be used for signing, only verifying signatures, from the given point. The
 * compression state of pub will be preserved.
 *
 * @param pub -
 * @return -
 */
public static ECKey fromPublicOnly(ECPoint pub) {
  return new ECKey(null, pub);
}
origin: yggdrash/yggdrash

/**
 * Account Constructor.
 * - generate wallet with new key
 */
public Account() {
  this.key = new ECKey();
  this.address = this.key.getAddress();
}
origin: yggdrash/yggdrash

/**
 * Creates an ECKey that cannot be used for signing, only verifying signatures, from the given encoded point.
 * The compression state of pub will be preserved.
 *
 * @param pub -
 * @return -
 */
public static ECKey fromPublicOnly(byte[] pub) {
  return new ECKey(null, CURVE.getCurve().decodePoint(pub));
}
origin: yggdrash/yggdrash

/**
 * Creates an ECKey given the private key only.
 *
 * @param privKey -
 * @return -
 */
public static ECKey fromPrivate(BigInteger privKey) {
  return new ECKey(privKey, CURVE.getG().multiply(privKey));
}
origin: yggdrash/yggdrash

@Test(expected = IllegalArgumentException.class)
public void testPrivatePublicKeyBytesNoArg() {
  // Expecting an IllegalArgumentException for using only null-parameters
  new ECKey((BigInteger) null, null);
}
origin: yggdrash/yggdrash

@Test(expected = IllegalArgumentException.class)
public void testInvalidPrivateKey() throws Exception {
  // Expecting an IllegalArgumentException for using an non EC private key
  PrivateKey privateKey = KeyPairGenerator.getInstance("DSA").generateKeyPair().getPrivate();
  new ECKey(
      Security.getProvider("SunEC"),
      privateKey,
      ECKey.fromPublicOnly(pubKey).getPubKeyPoint());
}
origin: yggdrash/yggdrash

@Test(expected = IllegalArgumentException.class)
public void testSignIncorrectInputSize() {
  // Expecting an IllegalArgumentException for a non 32-byte input
  ECKey key = new ECKey();
  String message = "The quick brown fox jumps over the lazy dog.";
  key.doSign(message.getBytes());
}
origin: yggdrash/yggdrash

private void encryptKeyFileInit(ECKey key, String keyPath, String keyName, String password)
    throws IOException, InvalidCipherTextException {
  if (key == null) {
    key = new ECKey();
origin: yggdrash/yggdrash

@Test
@SuppressWarnings("UnstableApiUsage")
public void testSValue() throws Exception {
  // 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(() -> key.doSign(hash)));
  }
  List<ECKey.ECDSASignature> sigs = Futures.allAsList(sigFutures).get();
  for (ECKey.ECDSASignature signature : sigs) {
    assertTrue(signature.s.compareTo(ECKey.HALF_CURVE_ORDER) <= 0);
  }
  final ECKey.ECDSASignature duplicate = new ECKey.ECDSASignature(sigs.get(0).r, sigs.get(0).s);
  assertEquals(sigs.get(0), duplicate);
  assertEquals(sigs.get(0).hashCode(), duplicate.hashCode());
}
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 testGetPrivKeyBytes() {
  ECKey key = new ECKey();
  assertNotNull(key.getPrivKeyBytes());
  assertEquals(32, key.getPrivKeyBytes().length);
}
origin: yggdrash/yggdrash

@Test
public void keyRecovery() {
  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);
    checkNotNull(key2);
    if (key.equals(key2)) {
      found = true;
      break;
    }
  }
  assertTrue(found);
}
origin: yggdrash/yggdrash

@Test
public void testECKey() {
  ECKey key = new ECKey();
  assertTrue(key.isPubKeyCanonical());
  assertNotNull(key.getPubKey());
  assertNotNull(key.getPrivKeyBytes());
  log.debug(Hex.toHexString(key.getPrivKeyBytes()) + " :Generated privkey");
  log.debug(Hex.toHexString(key.getPubKey()) + " :Generated pubkey");
}
origin: yggdrash/yggdrash

@Test
public void testEqualsObject() {
  ECKey key0 = new ECKey();
  ECKey key1 = ECKey.fromPrivate(privateKey);
  ECKey key2 = ECKey.fromPrivate(privateKey);
  assertNotEquals(key0, key1);
  assertEquals(key1, key1);
  assertEquals(key1, key2);
}
io.yggdrash.common.cryptoECKey<init>

Javadoc

Generates an entirely new keypair.

BouncyCastle will be used as the Java Security Provider

Popular methods of ECKey

  • 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.
  • verify
    Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key.
  • signatureToKey,
  • 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
  • CodeWhisperer alternatives
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