cn.zhuqi.mavenssh.ext.util.Coder.java Source code

Java tutorial

Introduction

Here is the source code for cn.zhuqi.mavenssh.ext.util.Coder.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.zhuqi.mavenssh.ext.util;

import java.security.MessageDigest;
import org.apache.commons.codec.binary.Base64;

/**
 * ??BASE64
 *
 * @author chen
 *
 */
public class Coder {

    public static final String KEY_SHA = "SHA";
    public static final String KEY_MD5 = "MD5";

    /**
     * BASE64
     *
     * @param key
     * @return
     * @throws Exception
     */
    public static byte[] decryptBASE64(String key) throws Exception {
        return Base64.decodeBase64(key);
    }

    /**
     * BASE64
     *
     * @param sign
     * @return
     * @throws Exception
     */
    public static String encryptBASE64(byte[] sign) throws Exception {
        return Base64.encodeBase64String(sign);
    }

    /**
     * MD5
     *
     * @param data
     * @return
     * @throws Exception
     */
    public static byte[] encryptMD5(byte[] data) throws Exception {
        MessageDigest md5 = MessageDigest.getInstance(KEY_MD5);
        md5.update(data);
        return md5.digest();
    }

    /**
     * SHA
     *
     * @param data
     * @return
     * @throws Exception
     */
    public static byte[] encryptSHA(byte[] data) throws Exception {
        MessageDigest sha = MessageDigest.getInstance(KEY_SHA);
        sha.update(data);
        return sha.digest();
    }
}