Java Code Examples for java.security.PublicKey#getClass()

The following examples show how to use java.security.PublicKey#getClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ECKey.java    From javasdk with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Generate a new keypair using the given Java Security Provider.
 * <p>
 * All private key operations will use the provider.
 */
public ECKey(Provider provider, SecureRandom secureRandom) {
    this.provider = provider;

    final KeyPairGenerator keyPairGen = ECKeyPairGenerator.getInstance(provider, secureRandom);
    final KeyPair keyPair = keyPairGen.generateKeyPair();

    this.privKey = keyPair.getPrivate();

    final PublicKey pubKey = keyPair.getPublic();
    this.publicKey = keyPair.getPublic();
    if (pubKey instanceof BCECPublicKey) {
        pub = ((BCECPublicKey) pubKey).getQ();
    } else if (pubKey instanceof ECPublicKey) {
        pub = extractPublicKey((ECPublicKey) pubKey);
    } else {
        throw new AssertionError(
                "Expected Provider " + provider.getName() +
                        " to produce a subtype of ECPublicKey, found " + pubKey.getClass());
    }
}
 
Example 2
Source File: ECKeySecp256k1.java    From aion with MIT License 6 votes vote down vote up
/**
 * Generate a new keypair using the given Java Security Provider.
 *
 * <p>All private key operations will use the provider.
 */
public ECKeySecp256k1(Provider provider, SecureRandom secureRandom) {
    this.provider = provider;

    final KeyPairGenerator keyPairGen = ECKeyPairGenerator.getInstance(provider, secureRandom);
    final KeyPair keyPair = keyPairGen.generateKeyPair();

    this.privKey = keyPair.getPrivate();

    final PublicKey pubKey = keyPair.getPublic();
    if (pubKey instanceof BCECPublicKey) {
        pub = ((BCECPublicKey) pubKey).getQ();
    } else if (pubKey instanceof ECPublicKey) {
        pub = extractPublicKey((ECPublicKey) pubKey);
    } else {
        throw new AssertionError(
                "Expected Provider "
                        + provider.getName()
                        + " to produce a subtype of ECPublicKey, found "
                        + pubKey.getClass());
    }
}
 
Example 3
Source File: ECKey.java    From gsc-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Generate a new keypair using the given Java Security Provider.
 *
 * <p>All private key operations will use the provider.
 */
public ECKey(Provider provider, SecureRandom secureRandom) {
    this.provider = provider;

    final KeyPairGenerator keyPairGen = ECKeyPairGenerator.getInstance(provider, secureRandom);
    final KeyPair keyPair = keyPairGen.generateKeyPair();

    this.privKey = keyPair.getPrivate();

    final PublicKey pubKey = keyPair.getPublic();
    if (pubKey instanceof BCECPublicKey) {
        pub = ((BCECPublicKey) pubKey).getQ();
    } else if (pubKey instanceof ECPublicKey) {
        pub = extractPublicKey((ECPublicKey) pubKey);
    } else {
        throw new AssertionError(
                "Expected Provider " + provider.getName()
                        + " to produce a subtype of ECPublicKey, found "
                        + pubKey.getClass());
    }
}
 
Example 4
Source File: ECKey.java    From wkcwallet-java with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a new keypair using the given Java Security Provider.
 *
 * All private key operations will use the provider.
 */
public ECKey(Provider provider, SecureRandom secureRandom) {
    this.provider = provider;

    final KeyPairGenerator keyPairGen = ECKeyPairGenerator.getInstance(provider, secureRandom);
    final KeyPair keyPair = keyPairGen.generateKeyPair();

    this.privKey = keyPair.getPrivate();

    final PublicKey pubKey = keyPair.getPublic();
    if (pubKey instanceof BCECPublicKey) {
        pub = ((BCECPublicKey) pubKey).getQ();
    } else if (pubKey instanceof ECPublicKey) {
        pub = extractPublicKey((ECPublicKey) pubKey);
    } else {
        throw new AssertionError("Expected Provider " + provider.getName() + " to produce a subtype of ECPublicKey, found "
                + pubKey.getClass());
    }
}
 
Example 5
Source File: ECKey.java    From tron-wallet-android with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a new keypair using the given Java Security Provider. <p> All private key operations
 * will use the provider.
 */
public ECKey(Provider provider, SecureRandom secureRandom) {
  this.provider = provider;

  final KeyPairGenerator keyPairGen = ECKeyPairGenerator.getInstance
      (provider, secureRandom);
  final KeyPair keyPair = keyPairGen.generateKeyPair();

  this.privKey = keyPair.getPrivate();

  final PublicKey pubKey = keyPair.getPublic();
  if (pubKey instanceof BCECPublicKey) {
    pub = ((BCECPublicKey) pubKey).getQ();
  } else if (pubKey instanceof ECPublicKey) {
    pub = extractPublicKey((ECPublicKey) pubKey);
  } else {
    throw new AssertionError(
        "Expected Provider " + provider.getName() +
            " to produce a subtype of ECPublicKey, found " +
            pubKey.getClass());
  }
}
 
Example 6
Source File: ECKey.java    From asf-sdk with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Generate a new keypair using the given Java Security Provider.
 *
 * All private key operations will use the provider.
 */
public ECKey(Provider provider, SecureRandom secureRandom) {
  this.provider = provider;

  KeyPairGenerator keyPairGen = ECKeyPairGenerator.getInstance(provider, secureRandom);
  KeyPair keyPair = keyPairGen.generateKeyPair();

  this.privKey = keyPair.getPrivate();
  PublicKey pubKey = keyPair.getPublic();

  if (pubKey instanceof BCECPublicKey) {
    pub = ((BCECPublicKey) pubKey).getQ();
  } else if (pubKey instanceof ECPublicKey) {
    pub = extractPublicKey((ECPublicKey) pubKey);
  } else {
    throw new AssertionError("Expected Provider "
        + provider.getName()
        + " to produce a subtype of ECPublicKey, found "
        + pubKey.getClass());
  }
}
 
Example 7
Source File: EdDSAEngine.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
@Override
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
    reset();
    if (publicKey instanceof EdDSAPublicKey) {
        key = (EdDSAPublicKey) publicKey;

        if (digest == null) {
            // Instantiate the digest from the key parameters
            try {
                digest = MessageDigest.getInstance(key.getParams().getHashAlgorithm());
            } catch (NoSuchAlgorithmException e) {
                throw new InvalidKeyException("cannot get required digest " + key.getParams().getHashAlgorithm() + " for private key.");
            }
        } else if (!key.getParams().getHashAlgorithm().equals(digest.getAlgorithm()))
            throw new InvalidKeyException("Key hash algorithm does not match chosen digest");
    } else {
        throw new InvalidKeyException("cannot identify EdDSA public key: " + publicKey.getClass());
    }
}