DRBG SecureRandom Strength And Reseeding
Request a DRBG SecureRandom at 256-bit strength with prediction resistance and reseeding, then read back the algorithm, provider and a HexFormat token.
Code
import java.security.DrbgParameters;
import java.security.SecureRandom;
import java.util.HexFormat;
public class DrbgConfig {
public static void main(String[] args) throws Exception {
// strength=256 的 DRBG:PR_AND_RESEED 同时开启预测抗性与重播种
SecureRandom drbg = SecureRandom.getInstance("DRBG",
DrbgParameters.instantiation(256,
DrbgParameters.Capability.PR_AND_RESEED,
"release-pipeline".getBytes()));
System.out.println("algorithm = " + drbg.getAlgorithm());
System.out.println("provider = " + drbg.getProvider().getName());
byte[] token = new byte[16];
drbg.nextBytes(token);
System.out.println("token = " + HexFormat.of().formatHex(token));
// 降低要求重开一个实例:strength 128 + 不做重播种
SecureRandom light = SecureRandom.getInstance("DRBG",
DrbgParameters.instantiation(128,
DrbgParameters.Capability.NONE, null));
System.out.println("light algorithm = " + light.getAlgorithm());
}
}How it works
The working surface is the class DrbgConfig — everything else is wiring.
Caveats
- No external surface — every behavior comes from the standard library.
Putting it to use
Output lines are prefixed (algorithm =, provider =, token =), making what each step changes easy to notice.
Core lines under the microscope
byte[] token = new byte[16];
drbg.nextBytes(token);
Interactive Tools for This Topic
Password Strength MeterScore a password from 0 to 100 based on length and character classes, and get clear suggestions to make it stronger. Everything runs locally.Argon2id Hash InfoEstimate Argon2id password-hash latency and memory usage, and check your parameters against OWASP 2024 minimum and recommended settings.bcrypt Cost EstimatorEstimate bcrypt cost factor latency and brute-force resistance, and get a recommended cost for your target hash time and attacker throughput.CORS Header Policy DebuggerSimulate browser CORS preflight and credential policies against server response headers to pinpoint blocked origins, methods, or headers and fix them.
FAQ
- What does DRBG SecureRandom Strength And Reseeding print when run?
- Execute the whole file; each printed line is prefixed with a label like `algorithm =`, `provider =`, `token =`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.