security.java

来自「OBPM是一个开源」· Java 代码 · 共 34 行

JAVA
34
字号
package cn.myapps.util;

import java.security.MessageDigest;

/**
 * The security
 */
public class Security {
    /**
     * Encrypt the string with the MD5 arithmetic
     * @param s Normal message that you want to convert.
     * @return The Encrypt string.
     * @throws Exception
     */
    public static String encodeToMD5(String s) throws Exception{
        if (s == null)
            return null;
        String digstr = "";
        MessageDigest MD = MessageDigest.getInstance("MD5");

        byte[] oldbyte = new byte[s.length()];
        for (int i = 0; i < s.length(); i++) {
            oldbyte[i] = (byte) s.charAt(i);
        }
        MD.update(oldbyte);

        byte[] newbyte = MD.digest(oldbyte);
        for (int i = 0; i < newbyte.length; i++) {
            digstr = digstr + newbyte[i];
        }

        return digstr;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?