Use SecureRandom instead of Random (#15459)

Make sure that SecureRadom is used whenever the random number
is used for cryptographic operations, e.g. as nonce/salt.

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-08-20 21:29:37 +02:00
committed by GitHub
parent e86998000e
commit 95ac2eb80b
7 changed files with 14 additions and 7 deletions

View File

@@ -15,6 +15,7 @@ package org.openhab.binding.millheat.internal.handler;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.List;
import java.util.Optional;
import java.util.Random;
@@ -107,7 +108,7 @@ public class MillheatAccountHandler extends BaseBridgeHandler {
private @NonNullByDefault({}) MillheatAccountConfiguration config;
private static String getRandomString(final int sizeOfRandomString) {
final Random random = new Random();
final Random random = new SecureRandom();
final StringBuilder sb = new StringBuilder(sizeOfRandomString);
for (int i = 0; i < sizeOfRandomString; ++i) {
sb.append(ALLOWED_NONCE_CHARACTERS.charAt(random.nextInt(ALLOWED_NONCE_CHARACTERS_LENGTH)));