On Wed, Mar 20, 2013 at 5:12 PM, Matt Caswell <fr...@baggins.org> wrote:
> On 20 March 2013 11:25, azhar jodatti <azhar...@gmail.com> wrote: > > byte[] bobPubKeyEnc = bobKpair.getPublic().getEncoded(); > > This is providing an encoded form of the public key, whereas your code > is expecting it as an integer. Use the following instead: > > DHPublicKey dhpubkey = (DHPublicKey)(bobKpair.getPublic()); > BigInteger bobPubKeyInt = dhpubkey.getY(); > βYes, Matt. This worked and it also generates same secret key at both the end :) :) :) Thanks a lot. You been a great help to me. One more query :). After generating secret key : byte[] bobSharedSecret = bobKeyAgree.generateSecret();//this generates secret key. Note : this key matches with C client secret key :) I am doing below stuff in JAVA : SecretKeyFactory skf = SecretKeyFactory.getInstance("DES"); DESKeySpec desSpec = new DESKeySpec(bobSharedSecret); this.secretKey = skf.generateSecret(desSpec); What is the equivalent of this in C? this.secretKey is an object of javax.crypto.SecretKey which I am using for symmetric encryption like this byte[] utf8 = plaintext.getBytes("UTF8"); Cipher c = Cipher.getInstance("DES"); c.init(Cipher.ENCRYPT_MODE, this.secretKey); byte[] encryptedText = c.doFinal(utf8); return new sun.misc.BASE64Encoder().encode(encryptedText); and decryption like this Cipher c = Cipher.getInstance("DES"); byte[] decryptBase64= new sun.misc.BASE64Decoder().decodeBuffer(incryptedData); c.init(Cipher.DECRYPT_MODE, this.secretKey); byte plaintext[] = c.doFinal(decryptBase64); return new String(plaintext,"UTF-8"); β > > Matt > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > User Support Mailing List openssl-users@openssl.org > Automated List Manager majord...@openssl.org > β β