diff --git a/kernel/kernel-keymanager-service/src/main/java/io/mosip/kernel/zkcryptoservice/service/impl/ZKCryptoManagerServiceImpl.java b/kernel/kernel-keymanager-service/src/main/java/io/mosip/kernel/zkcryptoservice/service/impl/ZKCryptoManagerServiceImpl.java index 004a3c32..c8fb075c 100644 --- a/kernel/kernel-keymanager-service/src/main/java/io/mosip/kernel/zkcryptoservice/service/impl/ZKCryptoManagerServiceImpl.java +++ b/kernel/kernel-keymanager-service/src/main/java/io/mosip/kernel/zkcryptoservice/service/impl/ZKCryptoManagerServiceImpl.java @@ -220,7 +220,10 @@ public ZKCryptoResponseDto zkDecrypt(ZKCryptoRequestDto cryptoRequestDto) { private int getRandomKeyIndex() { List indexes = dataEncryptKeystoreRepository.getIdsByKeyStatus(ZKCryptoManagerConstants.ACTIVE_STATUS); - int randomNum = ThreadLocalRandom.current().nextInt(0, indexes.size() + 1); + // Remove plus one ( + 1) because 10000 random number is generated + // but in DB we have indexes from 0 - 9999 only. + // So removed + 1 + int randomNum = ThreadLocalRandom.current().nextInt(0, indexes.size()); return indexes.get(randomNum); }