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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM