• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Converting Public Key

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I am implementing a network based diffie hellman. The two communicating parties need to exchange their public keys. How do I encode/decode them as hex string so I can conveniently send the public keys over the network in string packets ?

Thanks.

Regards,
Thotheolh.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

DIffie Hellman has nothing to do with public keys. It is used by two parties to negotiate a common secret key -- ie. it is used for symmetric crypto algorithms. It is not used for assymmetric (public private key) algorithms.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

As for how to encode, you can look into base64 or uuencode algorithms to get the binary into a text string. You can also convert it to hex -- as you mentioned -- but that is much less efficient.

Henry
 
Tay Thotheolh
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I understand DH is used to exchange keys or insecure channels. The public key I am talking about is the Alice and Bob public keys they exchange during their DH besides the P and G values.

The problem I am having now is not how to extract the byte[] from the public key but how do I recreate the byte[] of the public key sent across the network into a PublicKey object again. I have looked through the PublicKey java doc but it seems like there is no direct way for using the transfered byte[] and re-assemble them back to PublicKey objects.
 
Tay Thotheolh
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I have found a way to convert bytes to public key.

It's in "http://www.exampledepot.com/egs/javax.crypto/KeyAgree.html" and "http://www.javafaq.nu/java-example-code-189.html".
 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic