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

com.github.hetianyi.common.util.CodecUtil Maven / Gradle / Ivy

package com.github.hetianyi.common.util;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;


/**
 * 编码解码工具
 *
 * @author Jason He
 * @version 1.0.0
 * @since 1.0.1
 * @date 2020-01-18
 */
public class CodecUtil {

    /**
     * 计算输入字符串的md5
     * @param d
     * @return
     */
    public static String md5(String... d) {
        if (null == d || d.length == 0) {
            return null;
        }
        return String.valueOf(Hex.encodeHex(DigestUtils.md5(StringUtil.join(d))));
    }

    /**
     * 将输入字符串编码为base64字符串
     * @param d
     * @return
     */
    public static String encodeBase64(String... d) {
        if (null == d || d.length == 0) {
            return null;
        }
        return new String(Base64.encodeBase64(StringUtil.join(d).getBytes()));
    }

    /**
     * 将base64解码
     * @param d
     * @return
     */
    public static String decodeBase64(String d) {
        if (StringUtil.isNullOrEmpty(d)) {
            return null;
        }
        return new String(Base64.decodeBase64(d));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy