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();
    }
    }

  • 相关阅读:
    滚动加载图片
    轮播图
    各种插件
    IE兼容
    文字换行
    CSS3 transform用法
    隐藏手机号中间几位数
    js实现收藏,首页等功能
    loading练习
    animation练习
  • 原文地址:https://www.cnblogs.com/bsyx/p/4129434.html
Copyright © 2011-2022 走看看