zoukankan      html  css  js  c++  java
  • Sha256加密

    package com.zq.utils.encryption;

    import java.util.Random;

    import org.apache.shiro.crypto.hash.Sha256Hash;

    import com.zq.utils.string.StringUtils;

    /**
    *
    * Created by MyEclipse. Author: ChenBin E-mail: chenb@8000056.com Date:
    * 2016-5-23 Time: 下午3:10:37 Company: HuNan BwWan information technology co.,LTD
    * Web sites: http://www.8000056.com/
    */
    public class Sha256Utils {

    /**
    * Description : 加密
    *
    * @author : ChenBin
    * @date : 2016-3-11 上午11:05:16
    */
    public static String exec(String passWd, String salt) {
    if (StringUtils.compareTrim(passWd, salt))
    return new Sha256Hash(passWd, salt).toString();
    return null;
    }

    /**
    * Description :产生指定长度密码盐
    *
    * @author : ChenBin
    * @date : 2016-3-11 上午11:24:22
    * @param :
    * scope-产生密码盐的字符取值范围
    * @param :
    * length-密码盐长度
    */
    public final static String getSalt(String scope, int length) {
    if (!StringUtils.compareTrim(scope))
    return "";
    int len = scope.length();
    Random random = new Random();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < length; i++) {
    int num = random.nextInt(len);
    sb.append(scope.charAt(num));
    }
    return sb.toString();
    }

    public static void main(String[] args) {
    String scope = "abcdefghijklmnopqrstuvwxyz";
    System.out.println(Sha256Utils.getSalt(scope, 4));
    }

    }

    这个是java 代码怎么不能选择java区啊

  • 相关阅读:
    ABAP 表格控制(Table Control)和步循环
    ABAP中正则表达式的简单使用方法 (转老白BLOG)
    ABAP常用函数集锦
    ALV用例大全
    DXP 笔记
    STM32笔记——Power Controller(PWR)
    STM32之glossary
    STM32 解析futaba S-bus协议
    Windows下 vundle的安装和使用
    使用串口绘制实时曲线 —— SerialChart
  • 原文地址:https://www.cnblogs.com/rey888/p/8315897.html
Copyright © 2011-2022 走看看