package com.ft.membership.crypto.signature;

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

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 byte[] getBase64DecodedBytes(final String encodedString) {

        return BASE_64_DECODER.decode(encodedString.getBytes(StandardCharsets.UTF_8));
    }
}

@@ -546,24 +546,42 @@
 dString) %7B%0A%0A
+        try %7B%0A    
         retu
@@ -655,16 +655,272 @@
 TF_8));%0A
+        %7D catch(IllegalArgumentException e) %7B%0A            // We do not want a RuntimeException to be thrown when the string passed is not in valid Base64 scheme%0A            // as bad input is possible to the lib methods.%0A            return null;%0A        %7D%0A
     %7D%0A%7D%0A

Handle IllegalArgumentException due to bad input