I have small program that starts with exchanging session key for communication and for that it use diffie-hellmann protocol. In java first part is done like this:
KeyPairGenerator keyPairGenerator1 = KeyPairGenerator.getInstance("DH");
keyPairGenerator1.initialize(Skip.sDHParameterSpec);
KeyPair keyPair1 = keyPairGenerator1.generateKeyPair();
byte[] localKey1 = keyPair1.getPublic().getEncoded();
KeyAgreement keyAgreement1 = KeyAgreement.getInstance("DH");
keyAgreement1.init(keyPair1.getPrivate());
// getting remote key
keyAgreement1.doPhase(theirPublicKey2, true);
byte[] sharedKey1 = keyAgreement1.generateSecret();
then localKey is send to remote part, who sends back they part of data for calculation DH shared key. Problem, another program expects to get row data (big integer), and from java program I sent X509 encoded.
So how can I get that BigInteger (local Y value of DH protocol) from PublicKey? Or maybe there's another way to generate necessary DH parameters?