package com.netauth.utils;
import java.security.SecureRandom;
/**
*
* <p>
* SecureRandom随机数生成工具类
* </p>
*
* <p>
* 版权所有:北京信安世纪科技股份有限公司(c) 2020
* </p>
*
* @author: jlcui
* @date: 2022年4月20日下午3:42:42
*
*/
public class SecureRandomUtil {
/** 定义随机密码位数,设为11位随机数。 */
protected static int CRYP_STR_LENGTH = 11;
public static String serial() {
byte[] b = new byte[CRYP_STR_LENGTH];
SecureRandom sr = new SecureRandom();
sr.nextBytes(b);
String str = str(b);
return str;
}
protected static String str(byte[] b) {
final char[] str = ("1234567890").toCharArray();
char[] out = new char[b.length];
for (int i = 0; i < b.length; i++) {
int index = b[i] % str.length;
if (index < 0) {
index += str.length;
}
out[i] = str[index];
}
return new String(out);
}
}