Base64 encoding issue in Java

146 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

Import Base64 as android.util.Base64

encodeToString takes byte array and return String.

String encoded=Base64.encodeToString(byteArray); 

Details about Base64.encodeToString here