Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: DH Key Exchange and Blowfish

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default DH Key Exchange and Blowfish

    /------------------------------------------------------------------------------------------------
    / I have completely re-written this post to make my question clearer
    /------------------------------------------------------------------------------------------------

    I am trying to write a test server for a client (I am only interested in the server mechanisms not client). I wasn't able to see the codes for the client, but i know client

    - performs a DH exchange with server by first accepting server p, g, server public key
    - after formulating it's client shared key, client returns server it's own public key for server to establish shared key.
    - immediately client sends server a verification packet that is encrypted with blowfish using shared key as the blowfish key
    - server has to decode this verification msg

    I have set up my server to accommodate the above description, and having prior knowledge of what the decryption outcome(verification) would be, the result is not quite what i wanted. These are my codes used for DH exchange and blowfish, which part of it might have resulted in the unexpected decryption.

     
            //getting ready key objects
            KeyPairGenerator kpairGen = KeyPairGenerator.getInstance("DiffieHellman");
            DHParameterSpec dhparam = new DHParameterSpec(new BigInteger(P, 16), new BigInteger(G, 16));
            kpairGen.initialize(dhparam);
            KeyPair kpair = kpairGen.generateKeyPair();
            String ServerPrivateKey = ((DHPrivateKey) kpair.getPrivate()).getX().toString(16);
            String ServerPublicKey = ((DHPublicKey) kpair.getPublic()).getY().toString(16);
     
            //Send server p, g, public key to client
            ClientHandler.write( packetBuilder(P,G,ServerPublicKey) );
     
            //obtain client public key
            int byteRead = ClientHandler.read(packetBuffer);
            String ClientPublicKey = new String( trimPacket(packetBuffer,byteRead) );
     
            //Generate ServerClient SharedKey
            KeyAgreement agreement = KeyAgreement.getInstance("DiffieHellman");
            agreement.init(ServerPrivateKey);
            agreement.doPhase(ClientPublicKey, true);
            SecretKey sharedKey = agreement.generateSecret("Blowfish");
     
            //obtain client verification
            int byteRead = ClientHandler.read(packetBuffer);
            byte[] verification = trimPacket(packetBuffer,byteRead);
     
            //Decrypt the msg
            Cipher blowfish = Cipher.getInstance("Blowfish/CFB/NoPadding");
            blowfish.init(Cipher.DECRYPT_MODE, sharedKey, DecryptIV);
            byte[] result = blowfish.doFinal(p);
     
            //This result does not make any sense.


    Also, after obtaining the result, i have initialized the cipher to encrypt mode and encrypted the decoded msg. The before decryption verification packet is same as the post encryption verification packet; there isn't anything wrong with the way blowfish is carried out. So what's wrong with my key?
    Last edited by creepish; December 5th, 2010 at 02:29 PM. Reason: amending


  2. #2
    Junior Member
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: DH Key Exchange and Blowfish

    I have just updated my question. Please help.

Tags for this Thread