编辑代码

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;

public class EncryptUtil {


	public static void main(String[] args) {
		//String sql = "vbwLRC98BPmoNwT8GtnUlBn+xSvYkkj56EHUG7fFXaBs4Mrn3VPVVr+cmvuuTPyN2WBNQbnZc3HVSyc60wC95LE4Q1l7quXUbp+Qv12C3S3PshQv7WZM0HAx+cwAYvBYzAxX/NgwPZCyOw5IbpbUoXmzQXvZXH1MmwSSAqDcmT7jE8YzjhFKUeOOHRoNRJjXX7yc6Q6/oBltEjIPgFh9s4W+urG9WzZ0b9ykxhQz8Fpob2oBhoBYFu+zjUnsGwfEVWq2Bccbvg2KZ9rb/ZWvdmfGRuVrsUcN87CKJlz4hfRSxzuNABKG+639VKAyb18eOD6mQwfCnTXTF4dKsMoG2z17dVnlgQ3scL2qs4Gx7dN9DAYrCEnIwiyYyOMor5NyiAZmhEqibiap3yPuhrFRObeKBV69qhJz3TViaO7SfBhJgSwQwO8NpBCdzcUXso2HA5iKarDM3yPvxcVrA0P60l4728FE2m/OkO8qP7FQnRUHie0mfGWHdjMdn/ZKi8T93PvSFT9FoPoS0SvEwgPnyr+cmvuuTPyNL48EAOuiAXtGUUn8xCEnV+gCL4Ln5zaKeiuzOQ9wbuql6+hoTvOwj/+vePTAdEACs4LbFEFGkzQmR6dLhZ2pa7Pfs/V9hKjuPzSNocwNQM1+LoWb0GMLdc9WW/EHfDnkyFfxmeOSAEyt3s6/5rJ2/vJCdNrjW/zMovN559iMPvO6MYLFs5aAjQAs/EfR9POTgIPKn9mQCkVDXMJ8iSdzYLa6BKkmvAUwnDOUvAQlhHrbdYmIf4CacLL9FgBYKyfUchyEnjey8TJ+HCKl8Ul7v6QmVNZDCxXdhw1DO79Gvje6LJ2VaCsSs9vX2zJuK7XoYq8IVPls/4nPc3t6l8qg6hg9m2Q0HJ+OkxPOd8it7nBX89m1QdGrPxGcG4QvU6sYgcuq3BDCdtqDVcwlShHaDwNeNSFKxytz798lYsZOAi6NZlFO0YKxj/vmu6iaoP0Yh1kknEpfKgAOyo3Efbn7eidhrnpMLxnahwt6HfXzvfY4HmPDWDFk+E0v1OhOHlmdsqK2wjM3Qhwr5sR8aLA6E1zgYIWRYm0cdoQO/0tkA7akhh/sWyB1urVEJeBM8TwSHcney8heBTEV/VwNAMjCI9Uqrh+IkJ/rJtKKsflNXWsnI7ck5EsHf3Yf1CMVXhaSVu64qMCy3NLo7GE3wLRDyl+aHWGe0g5jGQGENwmEmUoA8TjSBhE0b8edFvEOqfDmOzx9y/Ro3ig=";
		//加密字符串填充到以下:
        String sql = "";
        System.out.println(decrypt(sql));
	}


    private static final String ALGORITHM = "DESede";

    //  24字节的密钥
    static final byte[] keyBytes = {0x11, 0x22, 0x4F, 0x58, (byte) 0x88, 0x10, 0x40, 0x38, 0x28,
            0x25, 0x79, 0x51, (byte) 0xCB, (byte) 0xDD, 0x55, 0x66, 0x77, 0x29, 0x74,
            (byte) 0x98, 0x30, 0x40, 0x36, (byte) 0xE2};
    public static String[] chars = new String[]{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
            "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8",
            "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
            "U", "V", "W", "X", "Y", "Z"};


    public static String encrypt(String info) {
        try {
            byte[] newInfo = encrypt(info.getBytes());
            return new BASE64Encoder().encode(newInfo).replaceAll("\r\n", "").replaceAll("\n", "");
        } catch (Exception ex) {
            return null;
        }

    }

    public static String decrypt(String info) {

        try {
            byte[] newInfo = decrypt(new BASE64Decoder().decodeBuffer(info));
            if (newInfo != null)
                return new String(newInfo);
        } catch (IOException ex) {
             ex.printStackTrace();
        }
        return null;

    }


    public static byte[] encrypt(byte[] info) {
        return cryptanalyze(Cipher.ENCRYPT_MODE, info);
    }


    public static byte[] decrypt(byte[] info) {
        return cryptanalyze(Cipher.DECRYPT_MODE, info);
    }


    private static byte[] cryptanalyze(int mode, byte[] info) {
        try {
            //生成密钥
            SecretKey deskey = new SecretKeySpec(keyBytes, ALGORITHM);
            //加密
            Cipher cipher = Cipher.getInstance(ALGORITHM);
            cipher.init(mode, deskey);
            byte[] newInfo = cipher.doFinal(info);
            return newInfo;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    private static MessageDigest digest = null;


    public synchronized static String hash(String data) {
        if (data == null || data == "") {
            return null;
        }
        final String algorithm = "MD5";
        if (digest == null) {
            try {
                digest = MessageDigest.getInstance(algorithm);
            } catch (NoSuchAlgorithmException nsae) {
                throw new RuntimeException("不支持该加密算法:" + algorithm);
            }
        }
        try {
            digest.update(data.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e.getMessage());
        }
        return encodeHex(digest.digest());
    }

    private static String encodeHex(byte[] bytes) {
        StringBuffer hex = new StringBuffer(bytes.length * 2);
        for (int i = 0; i < bytes.length; i++) {
            if (((int) bytes[i] & 0xff) < 0x10) {
                hex.append("0");
            }
            hex.append(Integer.toString((int) bytes[i] & 0xff, 16));
        }
        return hex.toString();
    }


    private static Random randGen = new Random();

    private static char[] numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz" +
            "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();

    public static final String randomString(int length) {
        if (length < 1) {
            return null;
        }
        // Create a char buffer to put random letters and numbers in.
        char[] randBuffer = new char[length];
        for (int i = 0; i < randBuffer.length; i++) {
            randBuffer[i] = numbersAndLetters[randGen.nextInt(71)];
        }
        return new String(randBuffer);
    }

}