zoukankan      html  css  js  c++  java
  • 密码加密(MD5)

    package com.sec.util;

    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;

    /**
    * 密码加密md5
    *
    * @author Administrator
    *
    */
    public class EncryptionUtil {
    public static String getEncryptionPassword(String userPwd)
    throws NoSuchAlgorithmException {

    // 1、转变为二进制(byte[])
    byte[] source = userPwd.getBytes();
    MessageDigest md5 = MessageDigest.getInstance("md5");
    // 2、将二进制更新
    md5.update(source);
    // 3、获取新摘要(byte[])
    source = md5.digest(source);
    // 4、重新转换为字符串
    int value;
    StringBuffer newPwd = new StringBuffer();
    for (byte b : source) {
    value = b & 0xff;// 保留低8位,其他位变零
    // 将8位的字节转换为16进制数 0-9 a-f(10-15)
    if (value <= 9) {
    newPwd.append("0");// 8 --> 08
    }
    newPwd.append(Integer.toHexString(value));
    }
    return newPwd.toString();
    }
    }

  • 相关阅读:
    安装wamp的方法及过程
    js原生获取className&多选一
    构造函数
    轮播图
    NaN
    ++与--运算练习
    if语句的练习
    switch语句的练习
    九九乘法表
    mac下git提交github代码
  • 原文地址:https://www.cnblogs.com/bsyx/p/4129434.html
Copyright © 2011-2022 走看看