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

com.soento.core.util.Base64Util Maven / Gradle / Ivy

package com.soento.core.util;

import org.apache.commons.codec.binary.Base64;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
 * @author soento
 */
public final class Base64Util {
    public static byte[] encrypt(byte[] input) {
        return Base64.encodeBase64(input);
    }

    public static String encrypt(byte[] input, Charset charset) {
        byte[] result = encrypt(input);
        return new String(result, charset);
    }

    public static String encrypt(String input, Charset charset) {
        return encrypt(input.getBytes(charset), charset);
    }

    public static String encrypt(String input) {
        return encrypt(input, StandardCharsets.UTF_8);
    }

    public static byte[] decrypt(byte[] input) {
        return Base64.decodeBase64(input);
    }

    public static String decrypt(byte[] input, Charset charset) {
        byte[] result = decrypt(input);
        return new String(result, charset);
    }

    public static String decrypt(String input, Charset charset) {
        return decrypt(input.getBytes(charset), charset);
    }

    public static String decrypt(String input) {
        return decrypt(input, StandardCharsets.UTF_8);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy