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区啊

原文地址:https://www.cnblogs.com/rey888/p/8315897.html