package io.domisum.lib.auxiliumlib.datacontainers;

import io.domisum.lib.auxiliumlib.annotations.API;
import io.domisum.lib.auxiliumlib.util.math.RandomUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Base64;

@API
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class UrlBase64
{
	
	// CONSTANTS
	@API
	public static final String CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-";
	
	
	// GENERATION
	@API
	public static String generate(int length)
	{
		var key = new StringBuilder();
		for(int i = 0; i < length; i++)
			key.append(getRandomCharacter());
		
		return key.toString();
	}
	
	private static char getRandomCharacter()
	{
		return CHARACTERS.charAt(RandomUtil.nextInt(CHARACTERS.length()));
	}
	
	
	// CODING
	@API
	public static byte[] decode(String urlBase64)
	{
		String base64 = urlBase64.replace('-', '+').replace('_', '/');
		return Base64.getDecoder().decode(base64);
	}
	
}

@@ -213,16 +213,58 @@
 uctor;%0A%0A
+import java.nio.charset.StandardCharsets;%0A
 import j
@@ -280,16 +280,16 @@
 Base64;%0A
-
 %0A@API%0A@N
@@ -906,106 +906,830 @@
 ing 
-base64 = urlBase64.replace('-', '+').replace('_', '/');%0A%09%09return Base64.getDecoder().decode(base64
+regularB64 = urlB64ToRegularB64(urlBase64);%0A%09%09return Base64.getDecoder().decode(regularB64);%0A%09%7D%0A%09%0A%09@API%0A%09public static String decodeToString(String urlBase64)%0A%09%7B%0A%09%09byte%5B%5D decoded = decode(urlBase64);%0A%09%09return new String(decoded, StandardCharsets.UTF_8);%0A%09%7D%0A%09%0A%09@API%0A%09public static String encode(byte%5B%5D data)%0A%09%7B%0A%09%09String regularBase64 = Base64.getEncoder().encodeToString(data);%0A%09%09return regularB64UrlB64To(regularBase64);%0A%09%7D%0A%09%0A%09@API%0A%09public static String encode(String data)%0A%09%7B%0A%09%09byte%5B%5D dataBytes = data.getBytes(StandardCharsets.UTF_8);%0A%09%09return encode(dataBytes);%0A%09%7D%0A%09%0A%09%0A%09@API%0A%09public static String urlB64ToRegularB64(String urlBase64)%0A%09%7B%0A%09%09return urlBase64.replace('-', '+').replace('_', '/');%0A%09%7D%0A%09%0A%09@API%0A%09public static String regularB64UrlB64To(String urlBase64)%0A%09%7B%0A%09%09return urlBase64.replace('+', '-').replace('/', '_'
 );%0A%09

Add more de- and encoding methods