0

I have private key (ecdsa,secp256r1).

private final static String SHA = "SHA-256";
        private final static String MODE = "EC";
        private final static String PROV = "SunEC";
        private final static String ECC_ALGO = "secp256r1";

public static KeyPair eccKeyGen() {


                KeyPairGenerator kpg;
                KeyPair kp = null;
                try {
                        kpg = KeyPairGenerator.getInstance(MODE, PROV);
                        ECGenParameterSpec ecsp;
                        ecsp = new ECGenParameterSpec(ECC_ALGO);
                        kpg.initialize(ecsp);
                        kp = kpg.genKeyPair();
                        return kp;
                } catch (Exception e) {
                        System.out.println("Key generation error.");
                        e.printStackTrace();
                }
                return kp;

How I can make public key from it in java without Bouncy Castle?

AlP
  • 21
  • 1
  • Possible duplicate of [How to get the RSA public-key from private-key Object in Java](https://stackoverflow.com/questions/24756420/how-to-get-the-rsa-public-key-from-private-key-object-in-java) – Yohannes Gebremariam Nov 06 '17 at 20:32

1 Answers1

-2

Assuming your private key is in an OpenSSH format, you can use the -y option for ssh-keygen. For example, if your private is contained in mykeythe following command will generate its public key

ssh-keygen -y -f mykey > mykey.pub
Frelling
  • 3,287
  • 24
  • 27
  • "Assuming your private key is in an OpenSSH format" How I can insert it in Java code? – AlP Nov 06 '17 at 20:49
  • Now that you added some code examples, I guess it is not an issue of having lost your public key. Are you asking if there are alternative JCE providers that can do the same as Bouncy Castle does? – Frelling Nov 09 '17 at 05:09