Since Java 8 there are handy utility classes directly in the standard library: Base64.Decoder and Base64.Encoder. There are also some static factory methods to construct instances of these classes which perform Base64 encoding/decoding for various flavors of Base64 in Base64 class.
This is how to use the encoder:
import java.util.Base64
import java.nio.charset.StandardCharsets
Base64.getEncoder.encodeToString("user:pass".getBytes(StandardCharsets.UTF_8))