• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
Sheriff
Posts: 28332
97
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.
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic