SecretKeyCreateUtil工具类,采用安全的生成随机数方法(SecureRandom),此处为10位

public class SecretKeyCreateUtil {
/**
* 产生密钥信息
* 采用安全的生成随机数方法(SecureRandom)
* @throws IOException
* @throws NoSuchAlgorithmException 
*/
public static String createSecretKey() throws IOException, NoSuchAlgorithmException {
final String base = "qwertyuiopasdfghjklzxcvbnm1234567890";
SecureRandom secureRandom=SecureRandom.getInstance("SHA1PRNG");
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < 10; i++) {
int number = sRandom.nextInt(base.length());
sb.append(base.charAt(number));
}
return sb.toString();
}
}

猜你喜欢

转载自blog.csdn.net/b13001216978/article/details/80533510
今日推荐