Java Code Examples for java.security.interfaces.ECPrivateKey#getParams()

The following examples show how to use java.security.interfaces.ECPrivateKey#getParams() . 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: KeyUtil.java    From snowblossom with Apache License 2.0 6 votes vote down vote up
/**
 * Get the EC curve parameters used by the secp256k1 keys used for HD seeds
 */
public static ECParameterSpec getECHDSpec()
{
  try
  {
    ECGenParameterSpec spec = new ECGenParameterSpec("secp256k1");
    KeyPairGenerator key_gen = KeyPairGenerator.getInstance("ECDSA", Globals.getCryptoProviderName());
    key_gen.initialize(spec);

    KeyPair pair = key_gen.genKeyPair();
    ECPrivateKey priv = (ECPrivateKey)pair.getPrivate();

    return priv.getParams();
  }
  catch(Exception e)
  {
    throw new RuntimeException(e);
  }

}
 
Example 2
Source File: P12Manager.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
public PublicKey getPublicKey()
        throws UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException,
                InvalidKeySpecException, NoSuchProviderException {
    ECPrivateKey privateKey = (ECPrivateKey) getPrivateKey();

    ECParameterSpec params = privateKey.getParams();

    org.bouncycastle.jce.spec.ECParameterSpec bcSpec =
            org.bouncycastle.jcajce.provider.asymmetric.util.EC5Util.convertSpec(params, false);
    org.bouncycastle.math.ec.ECPoint q = bcSpec.getG().multiply(privateKey.getS());
    org.bouncycastle.math.ec.ECPoint bcW = bcSpec.getCurve().decodePoint(q.getEncoded(false));
    ECPoint w =
            new ECPoint(
                    bcW.getAffineXCoord().toBigInteger(), bcW.getAffineYCoord().toBigInteger());
    ECPublicKeySpec keySpec = new ECPublicKeySpec(w, tryFindNamedCurveSpec(params));
    return (PublicKey)
            KeyFactory.getInstance("EC", BouncyCastleProvider.PROVIDER_NAME)
                    .generatePublic(keySpec);
}
 
Example 3
Source File: PEMManager.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
public PublicKey getPublicKey()
        throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException {
    ECPrivateKey privateKey = (ECPrivateKey) getPrivateKey();

    ECParameterSpec params = privateKey.getParams();

    org.bouncycastle.jce.spec.ECParameterSpec bcSpec =
            org.bouncycastle.jcajce.provider.asymmetric.util.EC5Util.convertSpec(params, false);
    org.bouncycastle.math.ec.ECPoint q = bcSpec.getG().multiply(privateKey.getS());
    org.bouncycastle.math.ec.ECPoint bcW = bcSpec.getCurve().decodePoint(q.getEncoded(false));
    ECPoint w =
            new ECPoint(
                    bcW.getAffineXCoord().toBigInteger(), bcW.getAffineYCoord().toBigInteger());
    ECPublicKeySpec keySpec = new ECPublicKeySpec(w, tryFindNamedCurveSpec(params));
    return (PublicKey)
            KeyFactory.getInstance("EC", BouncyCastleProvider.PROVIDER_NAME)
                    .generatePublic(keySpec);
}
 
Example 4
Source File: ECTesterStandalone.java    From ECTester with MIT License 6 votes vote down vote up
/**
 *
 */
private void export() throws NoSuchAlgorithmException, IOException {
    ProviderECLibrary lib = cfg.selected;
    KeyPairGeneratorIdent ident = null;
    String algo = cli.getOptionValue("export.type", "EC");
    for (KeyPairGeneratorIdent kpIdent : lib.getKPGs()) {
        if (kpIdent.contains(algo)) {
            ident = kpIdent;
            break;
        }
    }
    if (ident == null) {
        throw new NoSuchAlgorithmException(algo);
    }
    KeyPairGenerator kpg = ident.getInstance(lib.getProvider());
    if (cli.hasOption("export.bits")) {
        int bits = Integer.parseInt(cli.getOptionValue("export.bits"));
        kpg.initialize(bits);
    }
    KeyPair kp = kpg.genKeyPair();
    ECPrivateKey privateKey = (ECPrivateKey) kp.getPrivate();
    ECParameterSpec params = privateKey.getParams();
    System.out.println(params);
    EC_Curve curve = EC_Curve.fromSpec(params);
    curve.writeCSV(System.out);
}
 
Example 5
Source File: NativeSignatureSpi.java    From ECTester with MIT License 5 votes vote down vote up
@Override
protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
    if (!(privateKey instanceof ECPrivateKey)) {
        throw new InvalidKeyException
                ("Key must be an instance of ECPrivateKey");
    }
    signKey = (ECPrivateKey) privateKey;
    params = signKey.getParams();
    buffer.reset();
}
 
Example 6
Source File: NativeKeyAgreementSpi.java    From ECTester with MIT License 5 votes vote down vote up
@Override
protected void engineInit(Key key, SecureRandom random) throws InvalidKeyException {
    if (!(key instanceof ECPrivateKey)) {
        throw new InvalidKeyException
                ("Key must be instance of ECPrivateKey");
    }
    privateKey = (ECPrivateKey) key;
    this.params = privateKey.getParams();
}
 
Example 7
Source File: JCEECPrivateKey.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public JCEECPrivateKey(
    ECPrivateKey    key)
{
    this.d = key.getS();
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
}
 
Example 8
Source File: BCDSTU4145PrivateKey.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public BCDSTU4145PrivateKey(
    ECPrivateKey key)
{
    this.d = key.getS();
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
}
 
Example 9
Source File: BCECPrivateKey.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public BCECPrivateKey(
    ECPrivateKey key,
    ProviderConfiguration configuration)
{
    this.d = key.getS();
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
    this.configuration = configuration;
}
 
Example 10
Source File: BCECGOST3410PrivateKey.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public BCECGOST3410PrivateKey(
    ECPrivateKey key)
{
    this.d = key.getS();
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
}
 
Example 11
Source File: JCEECPrivateKey.java    From ripple-lib-java with ISC License 5 votes vote down vote up
public JCEECPrivateKey(
    ECPrivateKey    key)
{
    this.d = key.getS();
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
}
 
Example 12
Source File: BCDSTU4145PrivateKey.java    From ripple-lib-java with ISC License 5 votes vote down vote up
public BCDSTU4145PrivateKey(
    ECPrivateKey key)
{
    this.d = key.getS();
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
}
 
Example 13
Source File: BCECPrivateKey.java    From ripple-lib-java with ISC License 5 votes vote down vote up
public BCECPrivateKey(
    ECPrivateKey key,
    ProviderConfiguration configuration)
{
    this.d = key.getS();
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
    this.configuration = configuration;
}
 
Example 14
Source File: BCECGOST3410PrivateKey.java    From ripple-lib-java with ISC License 5 votes vote down vote up
public BCECGOST3410PrivateKey(
    ECPrivateKey key)
{
    this.d = key.getS();
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
}