• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Avec112 / commons-security / 18657491219

20 Oct 2025 03:49PM UTC coverage: 89.496% (+2.8%) from 86.722%
18657491219

push

github

Avec112
Rename builder `optional()` methods to `withMode()` and `withStrength()` and update references

- Refactored `EncryptBuilder` and `DecryptBuilder` to use `withMode()` and `withStrength()` methods for clarity and consistency.
- Updated `HybridCryptoTest` to reflect the method renaming.

27 of 40 branches covered (67.5%)

Branch coverage included in aggregate %.

399 of 436 relevant lines covered (91.51%)

3.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
src/main/java/io/github/avec112/security/crypto/random/RandomUtils.java
1
package io.github.avec112.security.crypto.random;
2

3

4
import io.github.avec112.security.encoding.EncodingUtils;
5

6
import java.security.NoSuchAlgorithmException;
7
import java.security.SecureRandom;
8

9
/**
10
 * The RandomUtils class provides utility methods for generating random values.
11
 */
12
public class RandomUtils {
13

14
    private static final SecureRandom SECURE_RANDOM;
15

16
    static {
17
        SecureRandom tmp;
18
        try {
19
            // Prefer the strongest available PRNG (may block briefly on some systems)
20
            tmp = SecureRandom.getInstanceStrong();
2✔
21
        } catch (NoSuchAlgorithmException e) {
×
22
            // Fallback: standard non-blocking SecureRandom
23
            tmp = new SecureRandom();
×
24
        }
1✔
25
        SECURE_RANDOM = tmp;
2✔
26
    }
1✔
27

28
    private RandomUtils() {
29
    }
30

31
    /**
32
     * Populates array with random bytes using SecureRandom
33
     * @param size length of byte array
34
     * @return random bytes
35
     */
36
    public static byte[] randomBytes(int size) {
37
        byte[] values = new byte[size];
3✔
38
        SECURE_RANDOM.nextBytes(values);
3✔
39
        return values;
2✔
40
    }
41

42
    /**
43
     * A randomized byte array (See randomBytes(..)) that is hex encoded
44
     * @param size SecureRandom byte size
45
     * @return hex encoded random bytes
46
     */
47
    public static String randomString(int size) {
48
        return EncodingUtils.hexEncode(randomBytes(size));
4✔
49
    }
50

51
    /**
52
     * Provides access to the singleton instance of SecureRandom used within the utility class.
53
     *
54
     * @return the shared SecureRandom instance for generating secure random values
55
     */
56
    public static SecureRandom secureRandom() {
57
        return SECURE_RANDOM;
2✔
58
    }
59

60
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc