public class NonceUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
MINIMUM_NONCE_LENGTH
The minimum required nonce length for validation by
validateNonce(ByteString). |
| Constructor and Description |
|---|
NonceUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
blockUntilSecureRandomSeeded()
Block until the
SecureRandom instance has been seeded. |
static void |
blockUntilSecureRandomSeeded(long timeout,
TimeUnit unit)
Block for at most
timeout waiting for the SecureRandom instance to be seeded. |
static void |
disableSecureRandom()
Disable the use of a
SecureRandom for nonce generation. |
static void |
enableSecureRandom()
Enable the use of a
SecureRandom for nonce generation. |
static ByteString |
generateNonce(int length) |
static ByteString |
generateNonce(SecurityPolicy securityPolicy)
Generate a nonce for the given
SecurityPolicy. |
static boolean |
isSecureRandomEnabled() |
static boolean |
isSecureRandomSeeded() |
static CompletionStage<Void> |
secureRandomSeeded()
Get a
CompletionStage that is completed when the SecureRandom instance has been seeded. |
static void |
validateNonce(ByteString nonce)
Validate that
nonce is at least MINIMUM_NONCE_LENGTH and is non-zeroes. |
static void |
validateNonce(ByteString nonce,
int minimumLength)
Validate that
nonce is at least minimumLength and is non-zeroes. |
static void |
validateNonce(ByteString nonce,
SecurityPolicy securityPolicy)
Validate that
nonce meets the minimum length requirement for securityPolicy and is non-zeroes. |
public static final int MINIMUM_NONCE_LENGTH
validateNonce(ByteString).
This is specified by OPC UA Part 4 to be least 32 bytes in the CreateSession and ActivateSession services.
public static void blockUntilSecureRandomSeeded()
throws ExecutionException,
InterruptedException
SecureRandom instance has been seeded.ExecutionException - if seeding completed exceptionally.InterruptedException - if the current thread was interrupted.public static void blockUntilSecureRandomSeeded(long timeout,
TimeUnit unit)
throws ExecutionException,
InterruptedException,
TimeoutException
timeout waiting for the SecureRandom instance to be seeded.timeout - the maximum time to wait.unit - the TimeUnit of the timeout argument.ExecutionException - if seeding completed exceptionally.InterruptedException - if the current thread was interrupted.TimeoutException - if the wait timed out.public static CompletionStage<Void> secureRandomSeeded()
CompletionStage that is completed when the SecureRandom instance has been seeded.CompletionStage that is completed when the SecureRandom instance has been seeded.public static void enableSecureRandom()
SecureRandom for nonce generation. This is the default.public static void disableSecureRandom()
SecureRandom for nonce generation. Not recommended.public static boolean isSecureRandomEnabled()
true is nonce generation uses a SecureRandom instance.public static boolean isSecureRandomSeeded()
true if the SecureRandom instance is seeded and available.public static ByteString generateNonce(int length)
length - the length of the nonce to generate.public static ByteString generateNonce(SecurityPolicy securityPolicy)
SecurityPolicy.
The length is determined by the policy: see getNonceLength(SecurityPolicy).
Important: this should only be used to generate a nonce exchanged when establishing a secure channel.
The nonce used by sessions has different length requirements.
securityPolicy - the SecurityPolicy to use when determining the nonce length.public static void validateNonce(ByteString nonce, SecurityPolicy securityPolicy) throws UaException
nonce meets the minimum length requirement for securityPolicy and is non-zeroes.
Important: this should only be used to validate the nonce exchanged when establishing a secure channel. The nonce used by sessions has different length requirements.
nonce - the nonce to validate.securityPolicy - the SecurityPolicy dictating the minimum nonce length.UaException - if nonce validation failed.public static void validateNonce(ByteString nonce) throws UaException
nonce is at least MINIMUM_NONCE_LENGTH and is non-zeroes.nonce - the nonce to validate.UaException - if nonce validation failed.public static void validateNonce(ByteString nonce, int minimumLength) throws UaException
nonce is at least minimumLength and is non-zeroes.nonce - the nonce to validate.minimumLength - the minimum required nonce lengthUaException - if nonce validation failed.Copyright © 2025. All rights reserved.