diff --git a/bundles/org.openhab.io.openhabcloud/src/main/java/org/openhab/io/openhabcloud/internal/CloudService.java b/bundles/org.openhab.io.openhabcloud/src/main/java/org/openhab/io/openhabcloud/internal/CloudService.java
index 66d65169b..e640c30b4 100644
--- a/bundles/org.openhab.io.openhabcloud/src/main/java/org/openhab/io/openhabcloud/internal/CloudService.java
+++ b/bundles/org.openhab.io.openhabcloud/src/main/java/org/openhab/io/openhabcloud/internal/CloudService.java
@@ -17,7 +17,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import java.security.SecureRandom;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -47,6 +46,7 @@ import org.openhab.core.model.script.engine.action.ActionService;
import org.openhab.core.net.HttpServiceUtil;
import org.openhab.core.types.Command;
import org.openhab.core.types.TypeParser;
+import org.openhab.core.util.StringUtils;
import org.openhab.io.openhabcloud.NotificationAction;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -80,8 +80,6 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
private static final int DEFAULT_LOCAL_OPENHAB_MAX_CONCURRENT_REQUESTS = 200;
private static final int DEFAULT_LOCAL_OPENHAB_REQUEST_TIMEOUT = 30000;
private static final String HTTPCLIENT_NAME = "openhabcloud";
- private static final String CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- private static final SecureRandom SR = new SecureRandom();
private final Logger logger = LoggerFactory.getLogger(CloudService.class);
@@ -292,14 +290,6 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
}
}
- private String randomString(int length) {
- StringBuilder sb = new StringBuilder(length);
- for (int i = 0; i < length; i++) {
- sb.append(CHARS.charAt(SR.nextInt(CHARS.length())));
- }
- return sb.toString();
- }
-
/**
* Creates a random secret and writes it to the userdata/openhabcloud
* directory. An existing secret
file won't be overwritten.
@@ -310,7 +300,7 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
String newSecretString = "";
if (!file.exists()) {
- newSecretString = randomString(20);
+ newSecretString = StringUtils.getRandomAlphanumeric(20);
logger.debug("New secret = {}", censored(newSecretString));
writeFile(file, newSecretString);
} else {