1

I have coded the following code to encode the byte[] str.

Byte[] str; 
Byte[] encoded=Base64.encodeToString(str); 

But Base64 word is not defined

I tried base64.encode() & base64.getEncoder()

I found a defined statement But I don't know how to use it:

byte[] encoded=Base64.encoder() 

How to use it? Or how can I encode a string or byte[] with or without libraries.

3
  • Firstly, Byte[] and byte[] aren't the same types. You almost certainly want byte[]. Next, to use the Base64 class in Android, you should import android.util.Base64. Commented May 6, 2020 at 15:49
  • Base64.encodeToString -> Don't try to push it into a byte array Commented May 6, 2020 at 15:49
  • Have you check the javadoc for Base64.encoder()? docs.oracle.com/javase/8/docs/api/java/util/Base64.Encoder.html Commented May 6, 2020 at 15:55

1 Answer 1

1

Import Base64 as android.util.Base64

encodeToString takes byte array and return String.

String encoded=Base64.encodeToString(byteArray); 

Details about Base64.encodeToString here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.