All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.global.api.utils.Base64Encoder Maven / Gradle / Ivy

There is a newer version: 14.2.3
Show newest version
package com.global.api.utils;

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

public class Base64Encoder implements IRequestEncoder {
    public String encode(Object value) {
        if(value == null) return null;
        byte[] encoded = Base64.getEncoder().encode(value.toString().getBytes(StandardCharsets.UTF_8));
        return new String(encoded);
    }

    public String decode(Object value) {
        if(value == null) return null;
        try {
            byte[] decoded = Base64.getDecoder().decode(value.toString().getBytes(StandardCharsets.UTF_8));
            return new String(decoded);
        }catch (IllegalArgumentException exception) {
            //Decoding failed, return the old object
            return value.toString();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy