package com.microstar.tap3.common;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

public class JWTUtils {

	public static String [] decoded(String JWTEncoded) throws Exception {
        try {
            String[] split = JWTEncoded.split("\\.");
            String [] ret = new String[2];
            ret[0] = getJson(split[0]);
            ret[1] = getJson(split[1]);
            
            return ret;
        } catch (UnsupportedEncodingException e) {
            //Error
        	e.printStackTrace();
        	return null;
        }
    }

	private static String getJson(String strEncoded) throws UnsupportedEncodingException{
        byte[] decodedBytes = Base64.getDecoder().decode(strEncoded);
        		//.decode(strEncoded, Base64.URL_SAFE);
        return new String(decodedBytes, "UTF-8");
    }
	
}
