I'm developing an application that will store ECC public keys in a database. I used a existing code to generate the keys, but when I use the method to get the public key from a private key, I get two values (x and y coordinates) returned. Is there a java-ready function that allows me to generate a public key from these two values? I found a link explaining how to do it, but I did not understand how to use the method.
package test;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.security.*;
import java.security.spec.*;
public class test {
public static void main(String[] args) {
KeyPairGenerator kpg;
kpg = KeyPairGenerator.getInstance("EC","SunEC");
ECGenParameterSpec ecsp;
ecsp = new ECGenParameterSpec("secp256r1");
kpg.initialize(ecsp);
String key;
KeyPair kp = kpg.genKeyPair();
PrivateKey privKey = kp.getPrivate();
PublicKey pubKey = kp.getPublic();
key = pubKey.toString().substring(46,125).concat(pubKey.toString().substring(142,220));
}
}