From 2f0c31fb02419198d83e321c2fb5d3a74e8e8349 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Wed, 25 Oct 2023 22:18:43 +1300 Subject: [PATCH] Change random key generator to use secure random generator (#1408) Signed-off-by: Chris Jackson --- .../java/com/zsmartsystems/zigbee/security/ZigBeeKey.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/security/ZigBeeKey.java b/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/security/ZigBeeKey.java index 69ce7f461..e136aa529 100644 --- a/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/security/ZigBeeKey.java +++ b/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/security/ZigBeeKey.java @@ -7,6 +7,7 @@ */ package com.zsmartsystems.zigbee.security; +import java.security.SecureRandom; import java.util.Arrays; import com.zsmartsystems.zigbee.IeeeAddress; @@ -245,9 +246,10 @@ public String toString() { * @return {@link ZigBeeKey} containing a random 128 bit key */ public static ZigBeeKey createRandom() { + SecureRandom secureRandom = new SecureRandom(); int key[] = new int[16]; for (int cnt = 0; cnt < 16; cnt++) { - key[cnt] = (int) Math.floor((Math.random() * 255)); + key[cnt] = secureRandom.nextInt(256); } return new ZigBeeKey(key);