package com.ft.membership.crypto.signature;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Optional;

public class Encoder {

    private static final Base64.Encoder BASE_64_ENCODER = Base64.getUrlEncoder().withoutPadding();
    private static final Base64.Decoder BASE_64_DECODER = Base64.getUrlDecoder();

    public static String getBase64EncodedString(final byte[] bytes) {

        return new String(BASE_64_ENCODER.encode(bytes), StandardCharsets.UTF_8);
    }

    public static Optional<byte[]> getBase64DecodedBytes(final String encodedString) {

        try {
            return Optional.of(BASE_64_DECODER.decode(encodedString.getBytes(StandardCharsets.UTF_8)));
        } catch(IllegalArgumentException e) {
            // We do not want a RuntimeException to be thrown when the string passed is not in valid Base64 scheme
            // as bad input is possible to the lib methods.
            return Optional.empty();
        }
    }
}

@@ -339,16 +339,140 @@
 der();%0A%0A
+    /**%0A     * Get Base64 encoded String of a byte array in UTF-8 charset%0A     *%0A     * @param bytes%0A     * @return%0A     */%0A
     publ
@@ -623,16 +623,148 @@
 %0A    %7D%0A%0A
+    /**%0A     * Get byte array in UTF-8 charset from Base64 encoded string%0A     *%0A     * @param encodedString%0A     * @return%0A     */%0A
     publ

Add javadocs with info on encoding