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

com.sc.channel.wxpay.utils.EncryptUtil Maven / Gradle / Ivy

The newest version!
package com.sc.channel.wxpay.utils;

import java.security.MessageDigest;
import java.util.Random;

public class EncryptUtil {
    private static final char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    private static final char[] chars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
            'h', 'i', 'g', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

    public final static String md5(String s) {
        try {
            byte[] btInput = s.getBytes("UTF-8");
            MessageDigest mdInst = MessageDigest.getInstance("MD5");
            mdInst.update(btInput);
            byte[] md = mdInst.digest();
            int j = md.length;
            char str[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(str);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    
    public static String random() {
        char[] array = new char[32];
        Random random = new Random();
        for (int i = 0; i < 32; i++) {
            int c = random.nextInt(36);
            array[i] = chars[c];
        }
        return new String(array);
    }

    public static void main(String[] args) {
        System.out.println(random());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy