• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Problem in doing Base64 encoding

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

My client wants to convert a string into MD5 and then get it base64 encoded. At his side, using some methods in C library, he did encoding as follows

plain text is siddhesh
md5: 9ca574b17a244ba0d8036e1387af1f2b
base64: nKV0sXokS6DYA24Th68fKw== (len=24)

Using Java Base64 class, I am not able to get value of "9ca574b17a244ba0d8036e1387af1f2b" as "nKV0sXokS6DYA24Th68fKw==".
I am getting larger value like "OWNhNTc0YjE3YTI0NGJhMGQ4MDM2ZTEzODdhZjFmMmI=" and same is the value when I do encoding using any online converter.

Any inputs on how to user Base64 class or some other technique with Java to get the Value as above in length of 24
 
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Siddhesh Deodhar wrote:My client wants to convert a string into MD5 and then get it base64 encoded.



That's most likely your problem right there. Because the purpose of Base64 encoding is to convert an array of bytes into an encoded string. It would help to see your code, but my guess is that at some point you're taking an array of bytes and illegitimately converting it to a String.
 
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you converting the actual MD5 byte values, or the String representation of those bytes? For instance the String value "F0" (2 characters) is different from the byte value 0xF0 (8 bits).
Edit: didn't see your response there Paul, when I wrote this. Basically you're hinting the same...
 
Siddhesh Deodhar
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul, Koen

I am now able to get the string in desired base64 encoded format. Yes, my mistake was that I was passing string value of MD5 output rather then byte array itself.
Thanks a lot.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic