KEYCLOAK-2148: Update HmacOTP to make use of SecureRandom
This commit is contained in:
parent
4a020d545b
commit
0d582a1326
1 changed files with 2 additions and 2 deletions
|
@ -3,7 +3,7 @@ package org.keycloak.models.utils;
|
||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Random;
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||||
|
@ -29,7 +29,7 @@ public class HmacOTP {
|
||||||
|
|
||||||
public static String generateSecret(int length) {
|
public static String generateSecret(int length) {
|
||||||
String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW1234567890";
|
String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW1234567890";
|
||||||
Random r = new Random();
|
SecureRandom r = new SecureRandom();
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
char c = chars.charAt(r.nextInt(chars.length()));
|
char c = chars.charAt(r.nextInt(chars.length()));
|
||||||
|
|
Loading…
Reference in a new issue