SecureRandomAlgorithm.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.utils.random;

  21. /**
  22.  * SecureRandomAlgorithm
  23.  *
  24.  * @author Poli Andrea (apoli@link.it)
  25.  * @author $Author$
  26.  * @version $Rev$, $Date$
  27.  */
  28. public enum SecureRandomAlgorithm {

  29.     // https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#securerandom-number-generation-algorithms
  30.    
  31.     // The algorithm names in this section can be specified when generating an instance of SecureRandom.

  32.     NATIVE_PRNG("NativePRNG"), // Obtains random numbers from the underlying native OS. No assertions are made as to the blocking nature of generating these numbers.
  33.     NATIVE_PRNG_BLOCKING("NativePRNGBlocking"), // Obtains random numbers from the underlying native OS, blocking if necessary. For example, /dev/random on UNIX-like systems.
  34.     NATIVE_PRNG_NON_BLOCKING("NativePRNGNonBlocking"), // Obtains random numbers from the underlying native OS, without blocking to prevent applications from excessive stalling. For example, /dev/urandom on UNIX-like systems.
  35.     PKCS11("PKCS11"), // Obtains random numbers from the underlying installed and configured PKCS #11 library.
  36.     DRBG("DRBG"), // An algorithm supplied by the SUN provider using DRBG mechanisms as defined in NIST SP 800-90Ar1.
  37.     SHA1PRNG("SHA1PRNG"), // The name of the pseudo-random number generation (PRNG) algorithm supplied by the SUN provider. This algorithm uses SHA-1 as the foundation of the PRNG. It computes the SHA-1 hash over a true-random seed value concatenated with a 64-bit counter which is incremented by 1 for each operation. From the 160-bit SHA-1 output, only 64 bits are used.
  38.     WINDOWS_PRNG("Windows-PRNG"); // Obtains random numbers from the underlying Windows OS.
  39.    
  40.     SecureRandomAlgorithm(String v){
  41.         this.value = v;
  42.     }
  43.    
  44.     private String value;

  45.     public String getValue() {
  46.         return this.value;
  47.     }
  48.     @Override
  49.     public String toString() {
  50.         return this.value;
  51.     }
  52. }