I want to use bouncycastle to specify the 32bytes private key to generate the public key corresponding to secp256k1, but I only see that bouncycastle generates the keypair directly. I need to know the base point G of the elliptic curve. How can I modify this code to achieve it?
private static ECKeyPair create(KeyPair keyPair) {
BCECPrivateKey privateKey = (BCECPrivateKey) keyPair.getPrivate();
BCECPublicKey publicKey = (BCECPublicKey) keyPair.getPublic();
BigInteger privateKeyVal = privateKey.getD();
byte[] publicKeyBytes = publicKey.getQ().getEncoded(false);
BigInteger publicKeyVal = new BigInteger(1, Arrays.copyOfRange(publicKeyBytes, 1, publicKeyBytes.length));
return new ECKeyPair(privateKeyVal, publicKeyVal);
}
public static ECKeyPair createECKeyPair() throws NoSuchProviderException, NoSuchAlgorithmException,
InvalidAlgorithmParameterException {
//Add bouncy castle as key pair gen provider
Security.addProvider(new BouncyCastleProvider());
//Generate key pair
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("ECDSA", "BC");
ECGenParameterSpec ecGenParameterSpec = new ECGenParameterSpec("secp256k1");
keyPairGenerator.initialize(ecGenParameterSpec, new SecureRandom());
//Convert KeyPair to ECKeyPair, to store keys as BigIntegers
return ECKeyPair.create(keyPairGenerator.generateKeyPair());
}