MD5 encryption

String sig = MD5Util.getMD5(unCodeStr.toString(), "UTF-8");

MD5 is a custom MD5 tool class:

/**
	 * getMD5
	 * @param message message
	 * @param code code
	 * @return MD5
	 */
	public static String getMD5(String message,String code) {
		String md5str = "";
		try {
			//1 Create an object that provides the information digest algorithm, initialized to the md5 algorithm object
			MessageDigest md = MessageDigest.getInstance("MD5");

			//2 Turn the message into a byte array
			byte[] input = message.getBytes(code);

			//3 After the calculation, the byte array is obtained, which is the 128 bits
			byte[] buff = md.digest(input);

			//4 Change each byte of the array (one byte occupies eight bits) into hexadecimal and connect them into an md5 string
			md5str = bytesToHex(buff);

		} catch (Exception e) {
			e.printStackTrace ();
		}
		return md5str;
	}
	

MessageDigest inherits from java.security.MessageDigestSpi:

public static MessageDigest getInstance(String algorithm)
    throws NoSuchAlgorithmException {
        try {
            Object[] objs = Security.getImpl(algorithm, "MessageDigest",
                                             (String)null);
            if (objs[0] instanceof MessageDigest) {
                MessageDigest md = (MessageDigest)objs[0];
                md.provider = (Provider)objs[1];
                return md;
            } else {
                MessageDigest delegate =
                    new Delegate((MessageDigestSpi)objs[0], algorithm);
                delegate.provider = (Provider)objs[1];
                return delegate;
            }
        } catch(NoSuchProviderException e) {
            throw new NoSuchAlgorithmException(algorithm + " not found");
        }
    }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325463937&siteId=291194637