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 String to Byte[] array

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



The above code is throwing error of:
Incompatible type
found: byte[]
required: java.lang.byte[]

Thanks in anticipation
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
You will need to create a Byte[] and set all the elements using a loop.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Wouter Oet wrote:You will need to create a Byte[] and set all the elements using a loop.




Same incompatible error

thanks again for helping
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
getBytes returns an array of bytes (primitive). To convert it into a Byte[] (wrapper) you'll need to create a new Byte[] and set the values of that.
Like this:


 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Wouter Oet wrote:getBytes returns an array of bytes (primitive). To convert it into a Byte[] (wrapper) you'll need to create a new Byte[] and set the values of that.
Like this:



Hello,

Thanks for your reply.


OUTPUT:
vpc_SecureHash=5DB0F8628C4801B24110FD52056WEJY5
Converted to=1f8a39f895956b6ebf5ae9268f27cd27
Converted to Original Hash=[B@136a1a1

Please check it again as to how can I convert back the hash (md5)

Best regards
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
On the whole it is very difficult to see what your code is trying to do so it is not obvious to me what you are asking.

Are you asking how to take a message digest and recover the message? If so you can't because a message digest is a one way algorithm. There are sites that say they can do this but all they do is maintain a large database of mappings from messages to digests. There are an infinite number of possible messages but only a finite number of digest values (2^16 for MD5) so for each digest value there are an infinite number of messages that can be used to create it.

Are you asking why
Converted to Original Hash=[B@136a1a1
is not what you expect? If so you should note that the toString() method of an array (your println() uses it behind the scenes) does not in any way reflect the content of that array. You will need to hex encode the content if you expect to see hex.

Please note - the line
does not preserve leading zeros so is a very bad way of converting a digest to a hex string. You would do better to use one of the open source libraries such as that from the Jakarta Codec project.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Farakh khan wrote:Please check it again as to how can I convert back the hash (md5)

You can't convert it back. It's a hash. That's basically one way encryption.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Wouter Oet wrote:

Farakh khan wrote:Please check it again as to how can I convert back the hash (md5)

You can't convert it back. It's a hash. That's basically one way encryption.



Thanks for replies

If this is one way encryption then what is mean by comparing has?

Best regards
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Let's continue the discussion in this duplicate thread, which is largely identical.
 
Get me the mayor's office! I need to tell him about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic