Exemplo n.º 1
0
  private static ASN1ObjectIdentifier getCurveId(final String curveName) {
    ASN1ObjectIdentifier curveId = X962NamedCurves.getOID(curveName);

    if (curveId == null) {
      curveId = SECNamedCurves.getOID(curveName);
    }

    if (curveId == null) {
      curveId = TeleTrusTNamedCurves.getOID(curveName);
    }

    if (curveId == null) {
      curveId = NISTNamedCurves.getOID(curveName);
    }

    return curveId;
  }
Exemplo n.º 2
0
  public static byte[] privateKeyToPublicKey(String private_key, boolean compressed) {
    byte[] privateKeyBytes = null;

    try {
      privateKeyBytes = org.apache.commons.codec.binary.Hex.decodeHex(private_key.toCharArray());
    } catch (DecoderException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    X9ECParameters ecp = SECNamedCurves.getByName("secp256k1");
    ECDomainParameters domainParams =
        new ECDomainParameters(ecp.getCurve(), ecp.getG(), ecp.getN(), ecp.getH(), ecp.getSeed());

    ECPrivateKeyParameters privateKey =
        new ECPrivateKeyParameters(new BigInteger(1, privateKeyBytes), domainParams);
    System.out.println(privateKey.getD());
    byte[] publicKeyBIBytes = privateKey.getD().toByteArray();
    ECPoint Q = domainParams.getG().multiply(new BigInteger(publicKeyBIBytes));

    byte[] publicKeyBytes = Q.getEncoded(compressed);
    return publicKeyBytes;
  }