java - Base 64 decoding byte[] casted into a string -


I have found some encoded log information, which is inserted in the string to send the purpose (the cast is very bad But it works).

I'm trying to put it back in [byte] so that it can decode it, but it is not working:

  byte [] encodedBytes = Android.util.Base64 encode ((login + ":" + password) .getBytes (), NO_WRAP); String encoded = "authentication" + encodedbits; String to _decode = encoded. Substring (17); Byte [] cast1 = to_decode; // error byte [] cast2 = (byte []) to_decode; // error byte [] cast3 = to_decode.getBytes (); // There is no error, but I get something completely from encodedibets (arrays also have half size of encoded bits) // and when I decode it, then I have an invalid argument exponent  

This 3 stoppage is not working, any thoughts?

There are many problems here.

In general, you use Base64.decode to use Base64.encode :

  byte [] Data is required to change the result of Android. Util.base64.decode (to_decode, default);  

In general, you should always ask yourself "How do I type W to type conversion from Type X?" How to type Y type while typing.

Note that you've got a typo in your code - "authentication" should be "authentication".

However, you've got a problem in your encoding too - you're making a byte , and using that string combination Here you can call toString () on the byte array, which no you want instead you should call encodeToString Here is a complete example :

  string prefix = "authentication"; // note is ok here ... // TODO: Do not use basic authentication; It is extremely insecure. // To avoid any ambiguity, note the obvious use of ASCII here and later. Byte [] rawData = (login + ":" + password) .getBytes (Standard Chart US_ASCII); String header = prefix + base64.exodostostring (raw data, NO_WRAP); // now to validate ... string toDecode = header.substring (prefix.length ()); Byte [] Decode Data = Base 64 Decode (Today Code, Default); System.out.println (new string (decoded data, standard charsets. US_ASCII));  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -