0

I have generated the ec private key from ec String. But I don't know how to get the ec public key from this public Key.

    KeyFactory keyFactory = KeyFactory.getInstance("EC");

    PrivateKey ecPrivateKey = readPrivateKey("MEECAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEJzAlAgEBBCDztZGe6gYyuO6r3RkPn9JzUZHLxa91\r\n" + " 8MadyUQSO7CrMw==\r\n" + " ", "EC");

    ECPrivateKey privateKey = (ECPrivateKey) ecPrivateKey;

    java.security.spec.ECParameterSpec ecSpec = privateKey.getParams();
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
    kpg.initialize(ecSpec);
    KeyPair kp = kpg.genKeyPair();
    ECPrivateKey priv = (ECPrivateKey) kp.getPrivate();
    ECPublicKey pub = (ECPublicKey) kp.getPublic();

But this publickey generated is not the correct public key.

shulin01
  • 11
  • 2

0 Answers0